/* Global Styles - Fixed Version */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary-color: #2c5282;
    --secondary-color: #4CAF50;
    --accent-color: #ffc107;
    --success-color: #28a745;
    --danger-color: #dc3545;
    --warning-color: #ff9800;
    --bg-light: #f5f7fa;
    --bg-white: #ffffff;
    --text-dark: #2d3748;
    --text-light: #718096;
    --border-color: #e2e8f0;
}

html, body {
    height: 100%;
    overflow-x: hidden;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background-color: var(--bg-light);
    color: var(--text-dark);
    line-height: 1.6;
}

/* Login Screen */
.login-screen {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    background: linear-gradient(135deg, var(--primary-color), #1a365d);
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
}

.login-container {
    background: white;
    padding: 40px;
    border-radius: 12px;
    box-shadow: 0 10px 40px rgba(0,0,0,0.2);
    width: 100%;
    max-width: 400px;
}

.login-header {
    text-align: center;
    margin-bottom: 30px;
}

.login-header i {
    font-size: 48px;
    color: var(--primary-color);
    margin-bottom: 15px;
}

.login-header h1 {
    font-size: 24px;
    margin-bottom: 8px;
    color: var(--text-dark);
}

.login-header p {
    color: var(--text-light);
    font-size: 14px;
}

.login-form .form-group {
    margin-bottom: 20px;
}

.login-form label {
    display: block;
    margin-bottom: 8px;
    font-weight: 500;
    color: var(--text-dark);
}

.login-form label i {
    margin-right: 8px;
    color: var(--primary-color);
}

.login-form input {
    width: 100%;
    padding: 12px 15px;
    border: 2px solid var(--border-color);
    border-radius: 6px;
    font-size: 14px;
    transition: border-color 0.3s;
}

.login-form input:focus {
    outline: none;
    border-color: var(--primary-color);
}

.btn-primary, .btn-secondary {
    width: 100%;
    padding: 12px 20px;
    border: none;
    border-radius: 6px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.btn-primary {
    background: var(--primary-color);
    color: white;
}

.btn-primary:hover {
    background: #1a365d;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(44, 82, 130, 0.3);
}

.btn-secondary {
    background: var(--text-light);
    color: white;
}

.btn-secondary:hover {
    background: #4a5568;
}

.error-message {
    background: #fee;
    color: var(--danger-color);
    padding: 10px;
    border-radius: 6px;
    margin-top: 15px;
    font-size: 14px;
    text-align: center;
}

.login-footer {
    margin-top: 20px;
    text-align: center;
    font-size: 12px;
    color: var(--text-light);
}

/* Main Application Layout - FIXED */
#mainApp {
    display: flex;
    height: 100vh;
    overflow: hidden;
}

/* Sidebar - FIXED */
.sidebar {
    background: var(--primary-color);
    color: white;
    width: 250px;
    min-width: 250px;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    flex-shrink: 0;
}

.sidebar-header {
    padding: 25px 20px;
    border-bottom: 1px solid rgba(255,255,255,0.1);
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
}

.sidebar-header i {
    font-size: 28px;
}

.sidebar-header h2 {
    font-size: 20px;
    font-weight: 600;
}

.sidebar-menu {
    flex: 1;
    list-style: none;
    padding: 20px 0;
    overflow-y: auto;
}

.sidebar-menu li {
    margin-bottom: 5px;
}

.sidebar-menu a {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 20px;
    color: rgba(255,255,255,0.8);
    text-decoration: none;
    transition: all 0.3s;
}

.sidebar-menu a:hover {
    background: rgba(255,255,255,0.1);
    color: white;
}

.sidebar-menu a.active {
    background: rgba(255,255,255,0.15);
    color: white;
    border-left: 4px solid var(--accent-color);
}

.sidebar-menu i {
    font-size: 18px;
    width: 20px;
}

.sidebar-footer {
    padding: 20px;
    border-top: 1px solid rgba(255,255,255,0.1);
    flex-shrink: 0;
}

/* Main Content - FIXED */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.topbar {
    background: white;
    padding: 20px 30px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
}

.topbar h1 {
    font-size: 24px;
    color: var(--text-dark);
}

.user-info {
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--text-light);
}

.user-info i {
    font-size: 24px;
}

/* View Content - FIXED */
.view-content {
    flex: 1;
    overflow-y: auto;
    padding: 30px;
}

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

.stat-card {
    background: white;
    padding: 25px;
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.08);
    display: flex;
    align-items: center;
    gap: 20px;
    transition: transform 0.3s;
}

.stat-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 4px 16px rgba(0,0,0,0.12);
}

.stat-icon {
    width: 60px;
    height: 60px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    color: white;
    flex-shrink: 0;
}

.stat-info h3 {
    font-size: 32px;
    font-weight: 700;
    color: var(--text-dark);
    margin-bottom: 5px;
}

.stat-info p {
    color: var(--text-light);
    font-size: 14px;
}

/* Dashboard Charts - FIXED */
.dashboard-charts {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
    gap: 20px;
    margin-bottom: 30px;
}

.chart-card {
    background: white;
    padding: 25px;
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}

.chart-card h3 {
    margin-bottom: 20px;
    color: var(--text-dark);
    font-size: 18px;
}

.chart-card canvas {
    max-height: 300px !important;
    height: 300px !important;
}

/* Recent Leads */
.recent-leads {
    background: white;
    padding: 25px;
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}

.recent-leads h3 {
    margin-bottom: 20px;
    color: var(--text-dark);
    font-size: 18px;
}

/* Lead Card */
.lead-card {
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 20px;
    margin-bottom: 15px;
    cursor: pointer;
    transition: all 0.3s;
}

.lead-card:hover {
    border-color: var(--primary-color);
    box-shadow: 0 2px 12px rgba(44, 82, 130, 0.1);
}

.lead-card-header {
    display: flex;
    justify-content: space-between;
    align-items: start;
    margin-bottom: 15px;
}

.lead-name {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-dark);
    margin-bottom: 5px;
}

.lead-business {
    color: var(--text-light);
    font-size: 14px;
}

.lead-scores {
    display: flex;
    gap: 10px;
    flex-shrink: 0;
}

.score-badge {
    padding: 5px 12px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
    white-space: nowrap;
}

.score-high {
    background: #d4edda;
    color: #155724;
}

.score-medium {
    background: #fff3cd;
    color: #856404;
}

.score-low {
    background: #f8d7da;
    color: #721c24;
}

.lead-card-body {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 15px;
    margin-bottom: 15px;
}

.lead-info-item {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    color: var(--text-light);
}

.lead-info-item i {
    color: var(--primary-color);
    flex-shrink: 0;
}

.lead-card-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-top: 15px;
    border-top: 1px solid var(--border-color);
}

.status-badge {
    padding: 5px 12px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
}

.status-new {
    background: #e3f2fd;
    color: #1565c0;
}

.status-contacted {
    background: #fff3e0;
    color: #e65100;
}

.status-qualified {
    background: #f3e5f5;
    color: #6a1b9a;
}

.status-converted {
    background: #e8f5e9;
    color: #2e7d32;
}

.status-lost {
    background: #ffebee;
    color: #c62828;
}

.commission-value {
    font-size: 16px;
    font-weight: 600;
    color: var(--success-color);
}

/* View Header - FIXED */
.view-header {
    background: white;
    padding: 20px;
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.08);
    margin-bottom: 20px;
}

.search-bar {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 15px;
    border: 2px solid var(--border-color);
    border-radius: 8px;
    margin-bottom: 15px;
    background: var(--bg-light);
}

.search-bar i {
    color: var(--text-light);
}

.search-bar input {
    border: none;
    background: transparent;
    flex: 1;
    font-size: 14px;
    outline: none;
}

.filter-controls {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.filter-controls select,
.filter-controls button {
    padding: 10px 15px;
    border: 2px solid var(--border-color);
    border-radius: 6px;
    font-size: 14px;
    background: white;
    cursor: pointer;
}

.filter-controls select:focus {
    outline: none;
    border-color: var(--primary-color);
}

#exportCSV {
    background: var(--secondary-color);
    color: white;
    border: none;
    font-weight: 600;
}

#exportCSV:hover {
    background: #45a049;
}

/* Table */
.table-container {
    background: white;
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.08);
    overflow: hidden;
}

.leads-list {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

/* Analytics Grid - FIXED */
.analytics-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(450px, 1fr));
    gap: 20px;
}

.analytics-card {
    background: white;
    padding: 25px;
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}

.analytics-card h3 {
    margin-bottom: 20px;
    color: var(--text-dark);
    font-size: 18px;
}

.analytics-card canvas {
    max-height: 250px !important;
    height: 250px !important;
}

/* Countries Grid - FIXED */
.countries-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 20px;
}

.country-card {
    background: white;
    padding: 25px;
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.08);
    transition: transform 0.3s;
    cursor: pointer;
}

.country-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 4px 16px rgba(0,0,0,0.12);
}

.country-header {
    display: flex;
    align-items: center;
    gap: 15px;
    margin-bottom: 20px;
}

.country-flag {
    font-size: 40px;
}

.country-name {
    font-size: 20px;
    font-weight: 600;
    color: var(--text-dark);
}

.country-stats {
    display: grid;
    gap: 10px;
}

.country-stat {
    display: flex;
    justify-content: space-between;
    padding: 10px 0;
    border-bottom: 1px solid var(--border-color);
}

.country-stat:last-child {
    border-bottom: none;
}

.country-stat-label {
    color: var(--text-light);
    font-size: 14px;
}

.country-stat-value {
    font-weight: 600;
    color: var(--text-dark);
}

/* Template Content - FIXED WIDTH */
.template-content {
    background: white;
    padding: 30px;
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.08);
    margin-top: 20px;
    max-width: 100%;
}

.template-selector {
    background: white;
    padding: 20px;
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.08);
    margin-bottom: 20px;
}

.template-selector label {
    display: block;
    margin-bottom: 10px;
    font-weight: 600;
    color: var(--text-dark);
}

.template-selector select {
    width: 100%;
    max-width: 500px;
    padding: 12px 15px;
    border: 2px solid var(--border-color);
    border-radius: 6px;
    font-size: 14px;
}

.email-template {
    margin-bottom: 30px;
}

.email-template h3 {
    margin-bottom: 15px;
    color: var(--primary-color);
}

.email-template-box {
    background: var(--bg-light);
    padding: 25px;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    margin-bottom: 15px;
    white-space: pre-wrap;
    font-family: 'Courier New', monospace;
    font-size: 14px;
    line-height: 1.8;
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
}

.copy-btn {
    background: var(--secondary-color);
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 600;
    transition: all 0.3s;
}

.copy-btn:hover {
    background: #45a049;
    transform: translateY(-2px);
}

/* Modal - FIXED */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.5);
    overflow-y: auto;
}

.modal-content {
    background: white;
    margin: 50px auto;
    padding: 30px;
    border-radius: 12px;
    width: 90%;
    max-width: 900px;
    max-height: 85vh;
    overflow-y: auto;
    position: relative;
}

.close {
    position: absolute;
    right: 20px;
    top: 20px;
    font-size: 30px;
    font-weight: bold;
    color: var(--text-light);
    cursor: pointer;
    transition: color 0.3s;
}

.close:hover {
    color: var(--text-dark);
}

/* Lead Detail */
.lead-detail-header {
    display: flex;
    justify-content: space-between;
    align-items: start;
    margin-bottom: 30px;
    padding-bottom: 20px;
    border-bottom: 2px solid var(--border-color);
}

.lead-detail-title h2 {
    font-size: 28px;
    color: var(--text-dark);
    margin-bottom: 8px;
}

.lead-detail-actions {
    display: flex;
    gap: 10px;
}

.btn-edit, .btn-delete {
    padding: 10px 20px;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 600;
    transition: all 0.3s;
}

.btn-edit {
    background: var(--primary-color);
    color: white;
}

.btn-delete {
    background: var(--danger-color);
    color: white;
}

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

.detail-section {
    background: var(--bg-light);
    padding: 20px;
    border-radius: 8px;
}

.detail-section h3 {
    font-size: 18px;
    color: var(--primary-color);
    margin-bottom: 15px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.detail-item {
    display: flex;
    justify-content: space-between;
    padding: 10px 0;
    border-bottom: 1px solid var(--border-color);
    gap: 15px;
}

.detail-item:last-child {
    border-bottom: none;
}

.detail-label {
    color: var(--text-light);
    font-size: 14px;
    flex-shrink: 0;
}

.detail-value {
    font-weight: 600;
    color: var(--text-dark);
    text-align: right;
    word-break: break-word;
}

.score-visual {
    margin-top: 15px;
}

.score-bar {
    background: #e0e0e0;
    height: 30px;
    border-radius: 15px;
    overflow: hidden;
    margin-bottom: 10px;
}

.score-fill {
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: 600;
    font-size: 14px;
    transition: width 0.5s ease;
}

.products-list {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 10px;
}

.product-tag {
    background: var(--primary-color);
    color: white;
    padding: 8px 15px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
}

.network-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 10px;
}

.network-tag {
    background: var(--accent-color);
    color: var(--text-dark);
    padding: 5px 12px;
    border-radius: 15px;
    font-size: 12px;
    font-weight: 600;
}

.stars {
    color: #ffd700;
    font-size: 18px;
}

/* Lead Research Section */
.research-section {
    background: white;
    padding: 25px;
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.08);
    margin-bottom: 20px;
}

.research-section h3 {
    margin-bottom: 20px;
    color: var(--text-dark);
    font-size: 20px;
}

.research-filters {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 15px;
    margin-bottom: 20px;
}

.research-filters input,
.research-filters select {
    padding: 12px 15px;
    border: 2px solid var(--border-color);
    border-radius: 6px;
    font-size: 14px;
}

.research-btn {
    background: var(--primary-color);
    color: white;
    border: none;
    padding: 12px 30px;
    border-radius: 6px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s;
}

.research-btn:hover {
    background: #1a365d;
    transform: translateY(-2px);
}

.research-results {
    margin-top: 20px;
}

/* Responsive - FIXED */
@media (max-width: 1024px) {
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .dashboard-charts {
        grid-template-columns: 1fr;
    }
    
    .analytics-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 768px) {
    #mainApp {
        flex-direction: column;
    }
    
    .sidebar {
        width: 100%;
        min-width: 100%;
        max-height: none;
    }
    
    .main-content {
        width: 100%;
    }
    
    .stats-grid {
        grid-template-columns: 1fr;
    }
    
    .countries-grid {
        grid-template-columns: 1fr;
    }
    
    .filter-controls {
        flex-direction: column;
    }
    
    .filter-controls select,
    .filter-controls button {
        width: 100%;
    }
}
