/* Reset & Base 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%);
    color: #333;
    line-height: 1.6;
    min-height: 100vh;
}

/* Header */
.header {
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid rgba(255, 255, 255, 0.3);
    padding: 1rem 0;
    position: sticky;
    top: 0;
    z-index: 1000;
}

.header-container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 0 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

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

.logo i {
    font-size: 2rem;
    color: #667eea;
}

.logo h1 {
    font-size: 1.5rem;
    font-weight: 700;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.header-controls {
    display: flex;
    align-items: center;
    gap: 2rem;
}

.refresh-indicator {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: #666;
}

.refresh-indicator i {
    animation: spin 2s linear infinite;
}

@keyframes spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

.date-range select {
    padding: 0.5rem 1rem;
    border: 1px solid #ddd;
    border-radius: 8px;
    background: white;
    font-size: 0.9rem;
}

/* Main Content */
.main-content {
    max-width: 1400px;
    margin: 0 auto;
    padding: 2rem;
    display: flex;
    flex-direction: column;
    gap: 2rem;
}

/* Section Headers */
section h2 {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 1.5rem;
    font-weight: 700;
    color: white;
    margin-bottom: 1.5rem;
    text-shadow: 0 2px 4px rgba(0,0,0,0.3);
}

section h2 i {
    color: #ffd700;
}

/* KPI Section */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 1.5rem;
}

.kpi-card {
    background: rgba(255, 255, 255, 0.95);
    border-radius: 16px;
    padding: 1.5rem;
    display: flex;
    align-items: center;
    gap: 1rem;
    box-shadow: 0 8px 32px rgba(0,0,0,0.1);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.3);
    transition: all 0.3s ease;
}

.kpi-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 12px 40px rgba(0,0,0,0.15);
}

.kpi-icon {
    width: 60px;
    height: 60px;
    border-radius: 12px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 1.5rem;
}

.kpi-content h3 {
    font-size: 0.9rem;
    color: #666;
    margin-bottom: 0.5rem;
}

.kpi-value {
    font-size: 2rem;
    font-weight: 700;
    color: #333;
    margin-bottom: 0.25rem;
}

.kpi-change {
    font-size: 0.85rem;
    font-weight: 600;
}

.kpi-change.positive {
    color: #10b981;
}

.kpi-change.negative {
    color: #ef4444;
}

/* Flow Section */
.flow-container {
    display: grid;
    grid-template-columns: 1fr 400px;
    gap: 2rem;
}

.flow-chart {
    background: rgba(255, 255, 255, 0.95);
    border-radius: 16px;
    padding: 2rem;
    box-shadow: 0 8px 32px rgba(0,0,0,0.1);
    backdrop-filter: blur(10px);
}

.flow-metrics {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.flow-step {
    background: rgba(255, 255, 255, 0.95);
    border-radius: 12px;
    padding: 1rem;
    display: flex;
    align-items: center;
    gap: 1rem;
    box-shadow: 0 4px 16px rgba(0,0,0,0.1);
}

.step-number {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
}

.step-content h4 {
    font-size: 0.9rem;
    color: #666;
    margin-bottom: 0.25rem;
}

.step-value {
    font-size: 1.25rem;
    font-weight: 700;
    color: #333;
}

.step-rate {
    font-size: 0.85rem;
    color: #10b981;
    font-weight: 600;
}

.flow-arrow {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    color: #667eea;
    font-size: 1.2rem;
    font-weight: 600;
}

.flow-arrow i {
    font-size: 1.5rem;
}

/* Campaign Section */
.campaign-container {
    display: grid;
    grid-template-columns: 1fr 500px;
    gap: 2rem;
}

.campaign-chart {
    background: rgba(255, 255, 255, 0.95);
    border-radius: 16px;
    padding: 2rem;
    box-shadow: 0 8px 32px rgba(0,0,0,0.1);
    backdrop-filter: blur(10px);
}

.campaign-table {
    background: rgba(255, 255, 255, 0.95);
    border-radius: 16px;
    padding: 2rem;
    box-shadow: 0 8px 32px rgba(0,0,0,0.1);
    backdrop-filter: blur(10px);
    overflow: auto;
}

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

.campaign-table th,
.campaign-table td {
    padding: 0.75rem;
    text-align: left;
    border-bottom: 1px solid #f0f0f0;
}

.campaign-table th {
    font-weight: 600;
    color: #333;
    background: #f8f9fa;
}

.loading {
    text-align: center !important;
    color: #666;
    font-style: italic;
}

/* Real-time Section */
.realtime-container {
    display: grid;
    grid-template-columns: 1fr 300px;
    gap: 2rem;
}

.realtime-chart {
    background: rgba(255, 255, 255, 0.95);
    border-radius: 16px;
    padding: 2rem;
    box-shadow: 0 8px 32px rgba(0,0,0,0.1);
    backdrop-filter: blur(10px);
}

.alert-panel {
    background: rgba(255, 255, 255, 0.95);
    border-radius: 16px;
    padding: 2rem;
    box-shadow: 0 8px 32px rgba(0,0,0,0.1);
    backdrop-filter: blur(10px);
}

.alert-panel h3 {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 1rem;
    margin-bottom: 1rem;
    color: #333;
}

.alert-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.alert-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem;
    border-radius: 8px;
    font-size: 0.85rem;
}

.alert-item.normal {
    background: #f0f9ff;
    color: #0891b2;
}

.alert-item.warning {
    background: #fffbeb;
    color: #d97706;
}

.alert-item.critical {
    background: #fef2f2;
    color: #dc2626;
}

.alert-item time {
    margin-left: auto;
    font-size: 0.75rem;
    color: #666;
}

/* Attribution Section */
.attribution-container {
    display: grid;
    grid-template-columns: 1fr 400px;
    gap: 2rem;
}

.attribution-chart {
    background: rgba(255, 255, 255, 0.95);
    border-radius: 16px;
    padding: 2rem;
    box-shadow: 0 8px 32px rgba(0,0,0,0.1);
    backdrop-filter: blur(10px);
}

.attribution-details {
    background: rgba(255, 255, 255, 0.95);
    border-radius: 16px;
    padding: 2rem;
    box-shadow: 0 8px 32px rgba(0,0,0,0.1);
    backdrop-filter: blur(10px);
}

.attribution-details h3 {
    font-size: 1.1rem;
    color: #333;
    margin-bottom: 1.5rem;
}

.attribution-list {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.attribution-item {
    display: flex;
    align-items: center;
    padding: 1rem;
    background: #f8f9fa;
    border-radius: 8px;
}

.source-name {
    flex: 1;
    font-weight: 600;
    color: #333;
}

.source-value {
    font-size: 1.1rem;
    font-weight: 700;
    color: #667eea;
    margin: 0 1rem;
}

.source-percent {
    font-size: 0.9rem;
    color: #666;
    min-width: 50px;
    text-align: right;
}

/* Footer */
.footer {
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    border-top: 1px solid rgba(255, 255, 255, 0.3);
    margin-top: 4rem;
    padding: 2rem 0;
}

.footer-content {
    max-width: 1400px;
    margin: 0 auto;
    padding: 0 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    color: #666;
}

.footer-links {
    display: flex;
    gap: 2rem;
}

.footer-links a {
    color: #667eea;
    text-decoration: none;
    font-weight: 500;
    transition: color 0.3s ease;
}

.footer-links a:hover {
    color: #764ba2;
}

/* Responsive */
@media (max-width: 1200px) {
    .flow-container,
    .campaign-container,
    .realtime-container,
    .attribution-container {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 768px) {
    .header-container {
        flex-direction: column;
        gap: 1rem;
    }
    
    .main-content {
        padding: 1rem;
    }
    
    .kpi-grid {
        grid-template-columns: 1fr;
    }
    
    .footer-content {
        flex-direction: column;
        gap: 1rem;
    }
}

/* Campaign Analysis Enhancements */
.campaign-row td {
    padding: 12px 8px !important;
    line-height: 1.4;
}

.campaign-row small {
    font-size: 0.75rem;
    opacity: 0.8;
}

.high-roi {
    color: #28a745 !important;
    font-weight: bold;
}

.medium-roi {
    color: #ffc107 !important;
    font-weight: bold;
}

.low-roi {
    color: #dc3545 !important;
    font-weight: bold;
}

.open-rate, .click-rate {
    font-weight: 600;
}

/* Campaign Insights */
.insights-container {
    margin-top: 2rem;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 1rem;
}

.insight-card {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    padding: 1rem;
    border-left: 4px solid;
}

.insight-card.success {
    border-left-color: #28a745;
}

.insight-card.warning {
    border-left-color: #ffc107;
}

.insight-card.info {
    border-left-color: #17a2b8;
}

.insight-title {
    font-weight: bold;
    margin-bottom: 0.5rem;
}

.insight-message {
    margin-bottom: 0.5rem;
    opacity: 0.9;
}

.insight-action {
    font-size: 0.85rem;
    opacity: 0.8;
    font-style: italic;
}

/* FTD Matching Section */
.ftd-matching-section {
    background: rgba(255, 255, 255, 0.95);
    border-radius: 12px;
    padding: 2rem;
    margin: 2rem;
    box-shadow: 0 8px 32px rgba(31, 38, 135, 0.37);
    backdrop-filter: blur(4px);
    border: 1px solid rgba(255, 255, 255, 0.18);
}

.ftd-matching-section h2 {
    margin-bottom: 1.5rem;
    color: #333;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.ftd-matching-container {
    display: flex;
    flex-direction: column;
    gap: 2rem;
}

/* FTD Controls */
.ftd-controls {
    display: flex;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
    padding: 1rem;
    background: rgba(102, 126, 234, 0.1);
    border-radius: 8px;
    border: 1px solid rgba(102, 126, 234, 0.2);
}

.ftd-controls .btn {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    padding: 0.75rem 1.5rem;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-weight: 600;
    transition: all 0.3s ease;
}

.ftd-controls .btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3);
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: #555;
    cursor: pointer;
}

.checkbox-label input[type="checkbox"] {
    width: 18px;
    height: 18px;
    accent-color: #667eea;
}

.ftd-status {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-left: auto;
}

.status-ready {
    color: #28a745;
}

.status-processing {
    color: #ffc107;
    animation: pulse 1.5s infinite;
}

.status-error {
    color: #dc3545;
}

/* FTD Summary Stats */
.ftd-summary {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
}

.ftd-stat-card {
    background: rgba(255, 255, 255, 0.9);
    border-radius: 8px;
    padding: 1.5rem;
    display: flex;
    align-items: center;
    gap: 1rem;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    border: 1px solid rgba(102, 126, 234, 0.1);
    transition: all 0.3s ease;
}

.ftd-stat-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.15);
}

.ftd-stat-icon {
    width: 50px;
    height: 50px;
    border-radius: 8px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 1.2rem;
}

.ftd-stat-content h3 {
    font-size: 0.9rem;
    font-weight: 600;
    color: #666;
    margin-bottom: 0.25rem;
}

.ftd-stat-value {
    font-size: 1.8rem;
    font-weight: 700;
    color: #333;
}

/* FTD Results Table */
.ftd-results {
    margin-top: 1rem;
}

.ftd-results h3 {
    margin-bottom: 1rem;
    color: #333;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.table-container {
    overflow-x: auto;
    border-radius: 8px;
    border: 1px solid rgba(0, 0, 0, 0.1);
}

.ftd-table {
    width: 100%;
    border-collapse: collapse;
    background: rgba(255, 255, 255, 0.95);
}

.ftd-table th {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 1rem;
    text-align: left;
    font-weight: 600;
    border-bottom: 2px solid rgba(255, 255, 255, 0.2);
}

.ftd-table td {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid rgba(0, 0, 0, 0.05);
}

.ftd-table tr:hover {
    background: rgba(102, 126, 234, 0.05);
}

.ftd-table .ftd-count {
    font-weight: 600;
    color: #667eea;
}

.ftd-table .ftd-amount {
    font-weight: 600;
    color: #28a745;
}

.ftd-table .conversion-rate {
    font-weight: 600;
}

.ftd-table .roi.positive {
    color: #28a745;
    font-weight: 600;
}

.ftd-table .roi.negative {
    color: #dc3545;
    font-weight: 600;
}

.ftd-table .loading {
    text-align: center;
    color: #666;
    font-style: italic;
    padding: 2rem;
}

/* FTD Insights */
.ftd-insights {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 1rem;
    margin-top: 1.5rem;
}

.ftd-insights .insight-card {
    background: rgba(255, 255, 255, 0.9);
    border-radius: 8px;
    padding: 1.5rem;
    border-left: 4px solid;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    transition: all 0.3s ease;
}

.ftd-insights .insight-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.15);
}

/* Responsive Design for FTD Section */
@media (max-width: 768px) {
    .ftd-controls {
        flex-direction: column;
        align-items: stretch;
        gap: 0.75rem;
    }
    
    .ftd-summary {
        grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    }
    
    .ftd-stat-card {
        padding: 1rem;
        gap: 0.75rem;
    }
    
    .ftd-stat-icon {
        width: 40px;
        height: 40px;
        font-size: 1rem;
    }
    
    .ftd-stat-value {
        font-size: 1.5rem;
    }
    
    .ftd-insights {
        grid-template-columns: 1fr;
    }
}

/* Animation for processing state */
@keyframes pulse {
    0% { opacity: 1; }
    50% { opacity: 0.5; }
    100% { opacity: 1; }
}