/**
 * Estilos principales de la aplicación.
 */

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background-color: #f5f5f5;
    color: #333;
    line-height: 1.6;
}

html, body, #app {
    width: 100%;
    height: 100%;
}

#app {
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: auto;
}

/* Header */
.header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 0;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    flex-shrink: 0;
}

.header-content {
    max-width: 1600px;
    margin: 0 auto;
    width: 100%;
    padding: 1.5rem 2rem;
}

.header h1 {
    font-size: 2rem;
    margin-bottom: 1.5rem;
    font-weight: 700;
}

.header-controls {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.search-section {
    display: flex;
    flex-direction: column;
    gap: 0.8rem;
}

.search-box {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    position: relative;
    width: 100%;
}

.search-input {
    flex: 1;
    padding: 0.75rem 1rem;
    border: 1px solid rgba(255,255,255,0.3);
    border-radius: 4px;
    background: rgba(255,255,255,0.95);
    color: #333;
    font-size: 1rem;
    transition: all 0.3s ease;
}

.search-input:focus {
    outline: none;
    background: white;
    box-shadow: 0 0 0 3px rgba(255,255,255,0.3);
}

.search-input::placeholder {
    color: #999;
}

.search-results {
    position: absolute;
    top: 100%;
    left: 0;
    width: 100%;
    background: white;
    border: 1px solid #ddd;
    border-top: none;
    max-height: 400px;
    overflow-y: auto;
    z-index: 100;
    border-radius: 0 0 4px 4px;
    max-height: 300px;
    overflow-y: auto;
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
    z-index: 10;
    display: block;
}

.search-result-item {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid #eee;
    cursor: pointer;
    transition: background 0.2s;
    color: #333;
    font-size: 0.95rem;
}

.search-result-item:hover {
    background: #f5f5f5;
}

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

.product-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.chip {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    background: rgba(255,255,255,0.2);
    border: 1px solid rgba(255,255,255,0.4);
    padding: 0.5rem 0.75rem;
    border-radius: 20px;
    color: white;
    font-size: 0.9rem;
}

.chip-close {
    background: none;
    border: none;
    color: white;
    cursor: pointer;
    font-size: 1.2rem;
    padding: 0;
    line-height: 1;
    transition: opacity 0.2s;
}

.chip-close:hover {
    opacity: 0.8;
}

.controls-row {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
    align-items: center;
}

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

.control-group label {
    font-weight: 500;
    color: white;
}

.select-control {
    padding: 0.5rem;
    border: 1px solid rgba(255,255,255,0.3);
    border-radius: 4px;
    background: rgba(255,255,255,0.95);
    color: #333;
    font-size: 0.95rem;
    cursor: pointer;
    transition: all 0.3s ease;
}

.select-control:focus {
    outline: none;
    background: white;
}

/* Botones */
.btn {
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: 4px;
    font-size: 1rem;
    cursor: pointer;
    transition: all 0.3s ease;
    font-weight: 500;
}

.btn-primary {
    background: rgba(255,255,255,0.2);
    border: 1px solid rgba(255,255,255,0.4);
    color: white;
}

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

.btn-success {
    background: #48bb78;
    color: white;
}

.btn-success:hover {
    background: #38a169;
}

.btn-secondary {
    background: #667eea;
    color: white;
}

.btn-secondary:hover {
    background: #5568d3;
}

.btn-outline {
    background: transparent;
    border: 1px solid #667eea;
    color: #667eea;
}

.btn-outline:hover {
    background: #667eea;
    color: white;
}

.btn-small {
    padding: 0.5rem 1rem;
    font-size: 0.9rem;
}

.btn-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: #333;
    padding: 0.5rem;
}

.btn-close:hover {
    color: #667eea;
}

/* Main container */
.main-container {
    flex: 1 1 auto;
    display: flex;
    gap: 1.5rem;
    padding: 1.5rem 2rem;
    max-width: 1600px;
    margin: 0 auto;
    width: 100%;
    overflow: visible;
    min-height: 600px;
}

.map-section {
    flex: 2 1 auto;
    position: relative;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    background: white;
    height: 600px;
    min-height: 600px;
}

#map {
    width: 100%;
    height: 600px;
    min-height: 600px;
}

.demo-label {
    position: absolute;
    top: 1rem;
    right: 1rem;
    background: #fd7e14;
    color: white;
    padding: 0.5rem 1rem;
    border-radius: 4px;
    font-size: 0.9rem;
    font-weight: 600;
    display: none;
    z-index: 5;
}

.map-legend {
    position: absolute;
    bottom: 1rem;
    left: 1rem;
    background: white;
    border-radius: 4px;
    padding: 1rem;
    box-shadow: 0 2px 6px rgba(0,0,0,0.1);
    z-index: 5;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
    font-size: 0.9rem;
}

.legend-item:last-child {
    margin-bottom: 0;
}

.legend-line {
    width: 30px;
    height: 3px;
}

.legend-line.potential {
    background: #0066cc;
    border-radius: 1px;
}

/* Top countries sidebar */
.top-countries-section {
    flex: 1;
    background: white;
    border-radius: 8px;
    padding: 1.5rem;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    overflow-y: auto;
}

.top-countries-section h2 {
    font-size: 1.3rem;
    margin-bottom: 1rem;
    color: #333;
}

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

.country-item {
    padding: 1rem;
    border: 1px solid #e0e0e0;
    border-radius: 6px;
    transition: all 0.3s ease;
}

.country-item:hover {
    border-color: #667eea;
    box-shadow: 0 2px 8px rgba(102, 126, 234, 0.2);
}

.country-header h3 {
    font-size: 1.1rem;
    margin-bottom: 0.5rem;
}

.country-metrics {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin-bottom: 1rem;
    font-size: 0.9rem;
}

.metric {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.metric-label {
    color: #666;
}

.metric-value {
    font-weight: 600;
    color: #667eea;
}

.metric-value.potential {
    color: #ff9900;
}

.empty-message {
    text-align: center;
    color: #888;
    padding: 2rem 0;
}

/* Loading spinner */
.loading-spinner {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    padding: 2rem;
}

.spinner {
    border: 3px solid #f3f3f3;
    border-top: 3px solid #667eea;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.loading-spinner p {
    color: #666;
    font-size: 0.95rem;
}

/* Error message */
.error-message {
    background: #f8d7da;
    color: #721c24;
    border: 1px solid #f5c6cb;
    border-radius: 4px;
    padding: 1rem;
    margin-bottom: 1rem;
}

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.5);
}

.modal-content {
    position: relative;
    background: white;
    border-radius: 8px;
    max-width: 600px;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 10px 40px rgba(0,0,0,0.2);
    width: 90%;
}

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

.modal-header h2 {
    font-size: 1.5rem;
    margin: 0;
}

.modal-body {
    padding: 1.5rem;
    overflow-y: auto;
    flex: 1;
}

.modal-footer {
    padding: 1rem 1.5rem;
    border-top: 1px solid #e0e0e0;
    display: flex;
    justify-content: flex-end;
    gap: 0.5rem;
}

/* Strategy content */
.strategy-section {
    margin-bottom: 1.5rem;
}

.strategy-section h3 {
    font-size: 1.15rem;
    margin-bottom: 0.75rem;
    color: #667eea;
    border-bottom: 2px solid #667eea;
    padding-bottom: 0.5rem;
}

.strategy-section p {
    margin-bottom: 0.5rem;
    line-height: 1.6;
}

.strategy-section ul {
    list-style: none;
    padding-left: 0;
}

.strategy-section li {
    margin-bottom: 1rem;
    padding-left: 1.5rem;
    position: relative;
}

.strategy-section li:before {
    content: "▸";
    position: absolute;
    left: 0;
    color: #667eea;
}

.strategy-section li strong {
    display: block;
    margin-bottom: 0.25rem;
}

.strategy-section li p {
    margin: 0.25rem 0;
    font-size: 0.95rem;
    color: #666;
}

.plan-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1rem;
}

.plan-period {
    border: 1px solid #e0e0e0;
    border-radius: 4px;
    padding: 1rem;
    background: #fafafa;
}

.plan-period h4 {
    color: #667eea;
    margin-bottom: 0.5rem;
    font-size: 1rem;
}

.plan-period ul {
    list-style: none;
}

.plan-period li {
    margin-bottom: 0.75rem;
    padding: 0;
    position: relative;
}

.plan-period li strong {
    display: block;
    font-size: 0.9rem;
}

.plan-period li p {
    margin: 0;
    font-size: 0.85rem;
    color: #666;
}

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

.kpi-table tr {
    border-bottom: 1px solid #e0e0e0;
}

.kpi-table td {
    padding: 0.75rem;
    text-align: left;
}

.kpi-table td:first-child {
    font-weight: 600;
    color: #667eea;
}

.kpi-table td:last-child {
    color: #666;
}

.modal-chart-container {
    position: relative;
    width: 100%;
    height: 300px;
    margin: 1rem 0;
    background-color: #fafafa;
    border-radius: 4px;
    padding: 0.5rem;
    border: 1px solid #eee;
}

/* Catálogo de Productos */
.catalog-category {
    border-bottom: 1px solid #e0e0e0;
    padding: 1rem 0;
}

/* Responsive */
@media (max-width: 1200px) {
    .main-container {
        flex-direction: column;
    }

    .map-section {
        flex: 1;
        min-height: 400px;
    }

    .top-countries-section {
        flex: 1;
        max-height: 400px;
    }

    .plan-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 768px) {
    .header-content {
        padding: 1rem;
    }

    .header h1 {
        font-size: 1.5rem;
        margin-bottom: 1rem;
    }

    .controls-row {
        gap: 0.5rem;
    }

    .control-group {
        font-size: 0.9rem;
    }

    .control-group label {
        display: none;
    }

    .main-container {
        padding: 1rem;
        gap: 1rem;
    }

    .modal-content {
        width: 95%;
        max-height: 90vh;
    }

    .search-results {
        right: 50px;
    }
}

/* Arrow markers for arc curves */
.arrow-marker {
    filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.3));
}

.arrow-head {
    filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.3));
}

/* Análisis y Gráficos */
.analysis-section {
    background-color: white;
    border-top: 1px solid #ddd;
    padding: 2rem;
    margin-top: 1rem;
    flex-shrink: 0;
    overflow-y: auto;
}

.analysis-section h2 {
    margin-bottom: 1.5rem;
    font-size: 1.5rem;
    color: #333;
}

.chart-container {
    position: relative;
    width: 100%;
    height: 400px;
    margin-bottom: 1.5rem;
    background-color: #fafafa;
    border-radius: 8px;
    padding: 1rem;
    border: 1px solid #eee;
}

.chart-container-horizontal {
    position: relative;
    width: 100%;
    height: 500px;
    margin-bottom: 1.5rem;
    background-color: #fafafa;
    border-radius: 8px;
    padding: 1rem;
    border: 1px solid #eee;
}

.chart-info {
    background-color: #f0f7ff;
    padding: 1rem;
    border-left: 4px solid #0066cc;
    border-radius: 4px;
    font-size: 0.95rem;
    color: #333;
}

.chart-info p {
    margin: 0;
}

.chart-info strong {
    font-weight: 600;
}

/* Indicador de carga - Spinner */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.3);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

.loading-overlay.active {
    opacity: 1;
    visibility: visible;
}

.loading-spinner {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
}

.spinner {
    width: 50px;
    height: 50px;
    border: 4px solid rgba(255, 255, 255, 0.3);
    border-top: 4px solid #667eea;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

.loading-text {
    color: white;
    font-size: 1.1rem;
    font-weight: 600;
    text-align: center;
}

.loading-subtext {
    color: rgba(255, 255, 255, 0.8);
    font-size: 0.9rem;
    text-align: center;
    margin-top: 0.5rem;
}

/* Insignia de fuente de datos */
.data-source-badge {
    display: inline-block;
    padding: 0.4rem 0.8rem;
    border-radius: 20px;
    font-size: 0.85rem;
    font-weight: 600;
    margin-top: 0.5rem;
}

.data-source-badge.real {
    background-color: #d4edda;
    color: #155724;
    border: 1px solid #c3e6cb;
}

.data-source-badge.fallback {
    background-color: #fff3cd;
    color: #856404;
    border: 1px solid #ffeeba;
}

.data-source-badge.loading {
    background-color: #d1ecf1;
    color: #0c5460;
    border: 1px solid #bee5eb;
}

