/* ==================== VARIABLES & THEMING ==================== */
:root {
    --primary-color: #667eea;
    --secondary-color: #764ba2;
    --accent-color: #ff6b6b;
    --bg-primary: #ffffff;
    --bg-secondary: #f5f5f5;
    --text-primary: #333333;
    --text-secondary: #666666;
    --border-color: #dddddd;
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.1);
    --shadow-md: 0 2px 8px rgba(0, 0, 0, 0.15);
    --shadow-lg: 0 4px 12px rgba(0, 0, 0, 0.2);
    --transition: all 0.3s ease;
}

body.dark-mode {
    --bg-primary: #1a1a2e;
    --bg-secondary: #16213e;
    --text-primary: #e0e0e0;
    --text-secondary: #b0b0b0;
    --border-color: #404060;
}

/* ==================== RESET & BASE ==================== */
* { margin: 0; padding: 0; box-sizing: border-box; }
html { scroll-behavior: smooth; }
body { font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; background-color: var(--bg-secondary); color: var(--text-primary); line-height: 1.6; transition: background-color 0.3s ease, color 0.3s ease; }

/* ==================== THEME TOGGLE ==================== */
.theme-toggle { position: fixed; top: 20px; right: 20px; z-index: 1000; width: 50px; height: 50px; border-radius: 50%; border: 2px solid var(--primary-color); background-color: var(--bg-primary); color: var(--text-primary); font-size: 1.5rem; cursor: pointer; display: flex; align-items: center; justify-content: center; transition: var(--transition); box-shadow: var(--shadow-md); }
.theme-toggle:hover { transform: scale(1.1); box-shadow: var(--shadow-lg); }

/* ==================== HERO HEADER ==================== */
.hero { background: linear-gradient(135deg, var(--primary-color) 0%, var(--secondary-color) 100%); color: white; padding: 80px 20px; text-align: center; box-shadow: var(--shadow-md); position: relative; overflow: hidden; }
.hero::before { content: ''; position: absolute; top: -50%; right: -50%; width: 200%; height: 200%; background: radial-gradient(circle, rgba(255,255,255,0.1) 1px, transparent 1px); background-size: 50px 50px; animation: float 20s linear infinite; }
@keyframes float { 0% { transform: translate(0, 0); } 100% { transform: translate(50px, 50px); } }
.hero-content { position: relative; z-index: 1; animation: slideDown 0.6s ease-out; }
@keyframes slideDown { from { opacity: 0; transform: translateY(-30px); } to { opacity: 1; transform: translateY(0); } }
.hero-content h1 { font-size: 2.8rem; margin-bottom: 10px; font-weight: 700; text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.2); }
.hero-content p { font-size: 1.1rem; opacity: 0.95; margin-bottom: 30px; }
.hero-stats { display: flex; justify-content: center; gap: 40px; margin-top: 30px; flex-wrap: wrap; }
.stat { display: flex; flex-direction: column; align-items: center; text-align: center; }
.stat-number { font-size: 2.5rem; font-weight: 700; display: block; }
.stat-label { font-size: 0.9rem; opacity: 0.85; margin-top: 5px; }

/* ==================== CONTAINER ==================== */
.container { max-width: 1400px; margin: 0 auto; padding: 40px 20px; }

/* ==================== DEBUG PANEL ==================== */
.debug-panel { background: var(--bg-primary); border: 1px solid var(--border-color); border-radius: 8px; padding: 20px; margin-bottom: 30px; box-shadow: var(--shadow-sm); }
.debug-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.debug-header h3 { margin: 0; font-size: 1rem; color: var(--primary-color); }
.toggle-btn { background: none; border: none; font-size: 1.2rem; cursor: pointer; color: var(--text-secondary); padding: 5px 10px; transition: var(--transition); }
.toggle-btn:hover { color: var(--primary-color); }
.debug-content { font-size: 0.85rem; font-family: 'Courier New', monospace; color: var(--text-secondary); line-height: 1.4; max-height: 200px; overflow-y: auto; }
.debug-content p { margin: 4px 0; }

/* ==================== ERROR MESSAGES ==================== */
.error-container { margin-bottom: 20px; }
.error-message { background-color: #ffebee; border: 1px solid #ef5350; border-radius: 4px; padding: 12px 15px; margin-bottom: 10px; display: flex; justify-content: space-between; align-items: center; }
.error-message button { background: none; border: none; font-size: 1.2rem; cursor: pointer; color: #ef5350; }

/* ==================== CONTROLS ==================== */
.controls-section { display: flex; gap: 20px; margin-bottom: 30px; flex-wrap: wrap; background: var(--bg-primary); padding: 20px; border-radius: 8px; box-shadow: var(--shadow-sm); }
.control-group { display: flex; align-items: flex-start; gap: 10px; flex-direction: column; }
.control-group label { font-weight: 600; color: var(--text-primary); white-space: nowrap; }
.control-group select { padding: 10px 15px; border: 2px solid var(--border-color); border-radius: 6px; background-color: var(--bg-primary); color: var(--text-primary); font-size: 1rem; cursor: pointer; transition: var(--transition); }

/* ==================== COUNTRY SELECTOR WIDGET ==================== */
.country-selector-widget {
    background: var(--bg-secondary);
    border: 2px solid var(--border-color);
    border-radius: 12px;
    overflow: hidden;
    max-width: 400px;
    box-shadow: var(--shadow-sm);
    transition: var(--transition);
}

/* Floating map widget styling */
.country-selector-widget.map-widget {
    position: absolute;
    top: 15px;
    right: 15px;
    z-index: 999;
    max-width: 320px;
    background: white;
    border: 2px solid var(--primary-color);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

.country-selector-widget.map-widget.collapsed .country-list {
    display: none;
}

.country-selector-widget:hover {
    box-shadow: var(--shadow-md);
    border-color: var(--primary-color);
}

.country-selector-widget.map-widget:hover {
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.25);
}

.widget-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--secondary-color) 100%);
    color: white;
    font-weight: 600;
    border-bottom: 2px solid var(--border-color);
}

.country-selector-widget.map-widget .widget-header {
    padding: 10px 12px;
    border-bottom: none;
}

.widget-title {
    font-size: 1rem;
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 1;
}

.country-selector-widget.map-widget .widget-title {
    font-size: 0.95rem;
    gap: 6px;
}

.widget-toggle-btn {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: white;
    width: 28px;
    height: 28px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.9rem;
    transition: var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    margin: 0 6px;
}

.widget-toggle-btn:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: scale(1.1);
}

.widget-toggle-btn.collapsed {
    transform: rotate(180deg);
}

.widget-clear-btn {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: white;
    width: 28px;
    height: 28px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 1.1rem;
    transition: var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
}

.widget-clear-btn:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: scale(1.1);
}

.country-list {
    max-height: 400px;
    overflow-y: auto;
    padding: 0;
    background: white;
}

.country-selector-widget.map-widget .country-list {
    max-height: 350px;
    border-top: 1px solid var(--border-color);
}

.country-item {
    display: flex;
    align-items: center;
    padding: 10px 12px;
    cursor: pointer;
    transition: var(--transition);
    border-bottom: 1px solid var(--border-color);
    user-select: none;
}

.country-selector-widget.map-widget .country-item {
    padding: 9px 10px;
    font-size: 0.9rem;
}

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

.country-item:hover {
    background: linear-gradient(90deg, rgba(102, 126, 234, 0.1) 0%, rgba(118, 75, 162, 0.1) 100%);
    transform: translateX(2px);
}

.country-selector-widget.map-widget .country-item:hover {
    transform: translateX(1px);
}

.country-item.selected {
    background: linear-gradient(90deg, #F59E0B 0%, #D97706 100%);
    color: white;
    font-weight: 600;
}

.country-flag {
    font-size: 1.8rem;
    margin-right: 12px;
    min-width: 30px;
    text-align: center;
}

.country-name {
    flex: 1;
    font-size: 0.95rem;
}

.country-checkbox {
    width: 20px;
    height: 20px;
    border: 2px solid var(--text-primary);
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-left: 8px;
    transition: var(--transition);
    background: white;
}

.country-item.selected .country-checkbox {
    background: white;
    border-color: white;
}

.country-checkbox::after {
    content: '';
    display: none;
    width: 6px;
    height: 12px;
    border: solid var(--text-primary);
    border-width: 0 2px 2px 0;
    transform: rotate(45deg);
}

.country-item.selected .country-checkbox::after {
    display: block;
    border-color: #F59E0B;
}

/* Scrollbar styling for country list */
.country-list::-webkit-scrollbar {
    width: 6px;
}

.country-list::-webkit-scrollbar-track {
    background: transparent;
}

.country-list::-webkit-scrollbar-thumb {
    background: var(--primary-color);
    border-radius: 3px;
}

.country-list::-webkit-scrollbar-thumb:hover {
    background: var(--secondary-color);
}

/* ==================== CONTROLS ==================== */
.btn-export, .btn-reset { padding: 10px 20px; border: 2px solid var(--primary-color); border-radius: 6px; background-color: transparent; color: var(--primary-color); font-weight: 600; cursor: pointer; transition: var(--transition); }
.btn-export:hover, .btn-reset:hover { background-color: var(--primary-color); color: white; }

/* ==================== SECTIONS ==================== */
.section { background: var(--bg-primary); border-radius: 12px; padding: 30px; margin-bottom: 30px; box-shadow: var(--shadow-sm); animation: fadeIn 0.5s ease-out; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
.section h2 { font-size: 1.8rem; margin-bottom: 20px; color: var(--text-primary); border-bottom: 3px solid var(--primary-color); padding-bottom: 10px; font-weight: 700; }
.section-subtitle { color: var(--text-secondary); font-size: 0.95rem; margin-top: -15px; margin-bottom: 15px; font-style: italic; }

/* ==================== LOADING ==================== */
.chart-loading, .section-loading { width: 100%; height: 40px; background: linear-gradient(90deg, var(--bg-secondary) 25%, rgba(255,255,255,0.2) 50%, var(--bg-secondary) 75%); background-size: 200% 100%; border-radius: 4px; animation: loading 1.5s infinite; margin-bottom: 20px; }
@keyframes loading { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }
.skeleton-card { background: linear-gradient(90deg, var(--bg-secondary) 25%, rgba(255,255,255,0.2) 50%, var(--bg-secondary) 75%); background-size: 200% 100%; border-radius: 8px; height: 150px; animation: loading 1.5s infinite; }

/* ==================== CARDS GRID ==================== */
.cards-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); gap: 20px; }
.summary-card { background: linear-gradient(135deg, var(--primary-color) 0%, var(--secondary-color) 100%); color: white; padding: 25px; border-radius: 12px; text-align: center; box-shadow: var(--shadow-md); transition: var(--transition); position: relative; overflow: hidden; }
.summary-card::before { content: ''; position: absolute; top: -50%; right: -50%; width: 200%; height: 200%; background: radial-gradient(circle, rgba(255,255,255,0.1) 1px, transparent 1px); background-size: 20px 20px; }
.summary-card:hover { transform: translateY(-8px); box-shadow: var(--shadow-lg); }
.summary-card h3 { font-size: 1.3rem; margin-bottom: 15px; font-weight: 600; position: relative; z-index: 1; }
.card-value { font-size: 2.2rem; font-weight: 700; margin-bottom: 5px; font-variant-numeric: tabular-nums; position: relative; z-index: 1; }
.card-label { font-size: 0.9rem; opacity: 0.9; margin-bottom: 10px; position: relative; z-index: 1; }
.card-factor { font-size: 0.85rem; opacity: 0.8; font-weight: 500; position: relative; z-index: 1; }

/* ==================== MAP ==================== */
.map-container { 
    width: 100%; 
    height: 500px; 
    border-radius: 12px; 
    overflow: hidden; 
    box-shadow: var(--shadow-md);
    position: relative;
    background: linear-gradient(135deg, #e0f2fe 0%, #f0f9ff 100%);
}

/* ==================== CHARTS ==================== */
.chart-container { width: 100%; height: 400px; border-radius: 8px; background: var(--bg-secondary); }

/* ==================== TABLES ==================== */
.table-container { overflow-x: auto; border-radius: 8px; box-shadow: var(--shadow-sm); }
.data-table { width: 100%; border-collapse: collapse; background: var(--bg-primary); }
.data-table thead { background: var(--primary-color); color: white; }
.data-table th, .data-table td { padding: 12px 15px; text-align: left; border-bottom: 1px solid var(--border-color); }
.data-table tbody tr:hover { background-color: var(--bg-secondary); }
.table-loading { text-align: center; color: var(--text-secondary); }

/* ==================== MATRIX ==================== */
.matrix-table { overflow-x: auto; border-radius: 8px; box-shadow: var(--shadow-sm); }
.matrix-table table { width: 100%; border-collapse: collapse; background: var(--bg-primary); }
.matrix-table th, .matrix-table td { padding: 12px; text-align: center; border: 1px solid var(--border-color); font-weight: 500; }
.matrix-table th { background: var(--primary-color); color: white; }
.matrix-table tbody tr:nth-child(odd) { background: var(--bg-secondary); }

/* ==================== INSIGHTS ==================== */
.insights-list { list-style: none; padding: 0; }
.insights-list li { padding: 12px 15px; margin-bottom: 10px; background: var(--bg-secondary); border-left: 4px solid var(--primary-color); border-radius: 4px; transition: var(--transition); }
.insights-list li:hover { background: var(--border-color); transform: translateX(5px); }
.insights-list li::before { content: "→ "; color: var(--primary-color); font-weight: 700; margin-right: 8px; }

/* ==================== FOOTER ==================== */
.footer { text-align: center; padding: 30px 20px; color: var(--text-secondary); border-top: 1px solid var(--border-color); margin-top: 40px; }
.footer a { color: var(--primary-color); text-decoration: none; transition: var(--transition); }
.footer a:hover { text-decoration: underline; }

/* ==================== RESPONSIVE ==================== */
@media (max-width: 768px) {
    .hero-content h1 { font-size: 1.8rem; }
    .hero-content p { font-size: 1rem; }
    .hero-stats { gap: 20px; }
    .stat-number { font-size: 1.8rem; }
    .section { padding: 20px; }
    .section h2 { font-size: 1.5rem; }
    .cards-grid { grid-template-columns: 1fr; }
    .map-container { height: 350px; }
    .chart-container { height: 300px; }
    .controls-section { flex-direction: column; }
    .control-group { flex-direction: column; width: 100%; }
    .control-group select, .btn-export, .btn-reset { width: 100%; }
    .country-selector-widget { max-width: 100%; }
    .country-selector-widget.map-widget { max-width: 280px; right: 10px; top: 10px; }
}

@media (max-width: 480px) {
    .hero-content h1 { font-size: 1.4rem; }
    .hero { padding: 40px 15px; }
    .container { padding: 20px 10px; }
    .section { padding: 15px; margin-bottom: 20px; }
    .section h2 { font-size: 1.3rem; }
    .card-value { font-size: 1.8rem; }
    .data-table th, .data-table td { padding: 8px 10px; font-size: 0.9rem; }
}

/* ==================== SCROLLBAR ==================== */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: var(--bg-secondary); }
::-webkit-scrollbar-thumb { background: var(--primary-color); border-radius: 5px; }
::-webkit-scrollbar-thumb:hover { background: var(--secondary-color); }

/* ==================== PRINT ==================== */
@media print {
    .debug-panel, .controls-section, .theme-toggle { display: none !important; }
    .section { page-break-inside: avoid; box-shadow: none; border: 1px solid var(--border-color); }
    body { background: white; }
}

/* ==================== ACCESSIBILITY ==================== */
@media (prefers-reduced-motion: reduce) {
    * { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
}

button:focus, select:focus, a:focus {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
}
