body {
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  background: linear-gradient(135deg, #6A0DAD 0%, #0077B6 100%); /* Morado a Azul */
  margin: 0;
  padding: 20px;
  min-height: 100vh;
  box-sizing: border-box;
  color: #333; 
}

.container {
  max-width: 1600px; 
  margin: 0 auto;
}

h1 {
  text-align: center;
  color: white;
  font-size: 2.3rem; 
  margin-bottom: 10px;
  text-shadow: 2px 2px 4px rgba(0,0,0,0.3);
}

.subtitle {
  text-align: center;
  color: rgba(255,255,255,0.9);
  font-size: 1.1rem; 
  margin-bottom: 25px;
}

.intro-section {
    background: rgba(255, 255, 255, 0.9);
    color: #333;
    padding: 20px;
    border-radius: 16px;
    margin-bottom: 30px;
    box-shadow: 0 8px 16px rgba(0,0,0,0.1);
    font-size: 0.95rem;
    line-height: 1.6;
}

.intro-section h2 {
    color: #005A8C; 
    margin-top: 0;
    margin-bottom: 10px;
    font-size: 1.3rem;
}
.intro-section h3 {
    color: #4A0072; 
    margin-top: 20px;
    margin-bottom: 10px;
    font-size: 1.15rem;
}
 .intro-section p, .intro-section ul {
    margin-bottom: 15px;
 }
 .intro-section ul {
    padding-left: 20px;
 }
 .intro-section strong {
    color: #6A0DAD; 
 }
 .intro-section .formula {
    background-color: #f0f4f8;
    padding: 10px;
    border-radius: 6px;
    font-family: 'Courier New', Courier, monospace;
    font-size: 0.9rem;
    margin: 10px 0;
    display: block;
    white-space: pre-wrap;
 }
 .intro-section a {
    color: #0077B6;
    text-decoration: none;
    font-weight: bold;
 }
 .intro-section a:hover {
    text-decoration: underline;
 }
 .final-note {
    margin-top: 20px;
    padding-top: 15px;
    border-top: 1px solid #ddd;
    font-style: italic;
 }
 .credits {
    margin-top:20px;
    font-size: 0.85rem;
    text-align: center;
    color: #555;
 }


.data-input-section { /* Removido #hourly-data-section ya que no se usa */
    background: rgba(255, 255, 255, 0.95);
    padding: 20px;
    border-radius: 16px;
    margin-top: 30px; 
    margin-bottom: 30px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.1);
}
.data-input-section h3 { /* Removido #hourly-data-section ya que no se usa */
    text-align: center;
    color: #4A0072;
    margin-bottom: 15px;
}
.tariff-input-container {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 20px;
    justify-content: center;
}
.tariff-input-container label {
    font-weight: 600;
}
.tariff-input-container input[type="number"] {
    padding: 8px;
    border-radius: 6px;
    border: 1px solid #ccc;
    width: 120px;
}

/* --- ESTILOS DE TABLA REVISADOS --- */
#energyDataTable {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 20px;
    font-size: 0.85rem;
    table-layout: auto; /* Permitir que el navegador ajuste anchos, o 'fixed' si se definen anchos específicos */
}

#energyDataTable th, 
#energyDataTable td {
    border: 1px solid #ddd;
    padding: 8px 6px; /* Ajustado el padding para mejor espaciado */
    text-align: left;
    vertical-align: middle; /* Importante si los encabezados envuelven texto */
}

#energyDataTable th {
    background-color: #f2f2f2;
    color: #333;
    font-weight: 600;
    /* white-space: nowrap; */ /* Comentado para permitir que el texto del encabezado se ajuste. */
                               /* Si se prefiere nowrap, se necesitarían min-widths más agresivos. */
}

/* Anchos mínimos sugeridos para encabezados para mejorar la legibilidad */
/* Puedes ajustar estos valores según tus preferencias */
#energyDataTable th:nth-child(1) { min-width: 100px; } /* Tipo Energía */
#energyDataTable th:nth-child(2) { min-width: 100px; } /* Localización */
#energyDataTable th:nth-child(3) { min-width: 100px; } /* Área */
#energyDataTable th:nth-child(4) { min-width: 180px; } /* Equipo/Electrodoméstico */
#energyDataTable th:nth-child(5) { min-width: 50px; text-align: center; }  /* Cant. */
#energyDataTable th:nth-child(6) { min-width: 80px; text-align: right; }  /* Potencia (W) */
#energyDataTable th:nth-child(7) { min-width: 80px; text-align: right; }  /* Horas Uso/Día */
#energyDataTable th:nth-child(8) { min-width: 80px; text-align: right; }  /* Días Uso/Mes */
#energyDataTable th:nth-child(9) { min-width: 70px; text-align: right; }  /* F. Carga (%) */
#energyDataTable th:nth-child(10) { min-width: 70px; text-align: right; } /* F. Simult. (%) */
#energyDataTable th:nth-child(11) { min-width: 100px; text-align: right; } /* Consumo Wh/Día */
#energyDataTable th:nth-child(12) { min-width: 110px; text-align: right; } /* Consumo Wh/Mes */
#energyDataTable th:nth-child(13) { min-width: 110px; text-align: right; } /* Costo Wh/Mes (COP) */
#energyDataTable th:nth-child(14) { min-width: 60px; text-align: center; } /* Acción */


#energyDataTable input[type="text"], 
#energyDataTable input[type="number"], 
#energyDataTable select { 
    width: 100%; 
    padding: 6px 8px; /* Padding consistente */
    box-sizing: border-box;
    border: 1px solid #ccc;
    border-radius: 4px;
    font-size: 0.85rem; 
    height: auto; /* Permitir que el padding defina la altura */
    line-height: normal; /* Resetear line-height para inputs */
}

#energyDataTable input[type="number"] {
    text-align: right;
}

#energyDataTable .calculated-field { 
    background-color: #f0f0f0;
    font-weight: bold;
    padding: 7px 6px; 
    display: block; 
    width: 100%;
    box-sizing: border-box;
    min-width: 60px; 
    text-align: right;
    border-radius: 4px;
    line-height: normal; /* Para consistencia con inputs */
}
/* --- FIN ESTILOS DE TABLA REVISADOS --- */

.table-actions {
    text-align: center;
    margin-bottom: 20px;
}
.table-actions button, #hourly-data-controls button {
    background-color: #0077B6;
    color: white;
    border: none;
    padding: 10px 18px;
    border-radius: 8px;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: background-color 0.3s ease;
    margin: 5px; 
}
.table-actions button:hover, #hourly-data-controls button:hover {
    background-color: #005A8C;
}
.delete-row-btn, .delete-col-btn { 
    background-color: #dc3545 !important;
    padding: 4px 8px !important;
    font-size: 0.8rem !important;
    line-height: 1.2; 
    margin-left: 5px; 
}
.delete-row-btn:hover, .delete-col-btn:hover {
    background-color: #c82333 !important;
}

.controls {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 15px;
  margin-bottom: 30px;
  padding: 20px;
  background: rgba(255,255,255,0.1);
  border-radius: 16px;
  backdrop-filter: blur(10px);
  box-shadow: 0 8px 16px rgba(0,0,0,0.1); 
}

.filter-group {
  display: flex;
  flex-direction: column;
}

.filter-group label {
  color: white;
  font-weight: 600;
  margin-bottom: 8px;
  font-size: 0.9rem;
}

select { /* Estilo global para selects, asegurar que no interfiera con el de la tabla */
  font-size: 1rem;
  padding: 12px 16px;
  border-radius: 12px;
  border: none;
  background: white;
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
  transition: all 0.3s ease;
  cursor: pointer;
  color: #333; 
}
/* Selects dentro de la tabla ya tienen estilos más específicos */
#energyDataTable select {
  padding: 6px 8px; /* Sobrescribir el padding global para selects en tabla si es necesario */
  border-radius: 4px; /* Y otros estilos específicos de tabla */
  font-size: 0.85rem;
  /* Otros estilos específicos de la tabla pueden ir aquí */
}


select:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(0,0,0,0.15);
}

select:focus {
  outline: none;
  box-shadow: 0 0 0 3px rgba(0, 119, 182, 0.5); 
}

#chart-container, .chart-section {
  background: white;
  padding: 20px; 
  border-radius: 20px;
  box-shadow: 0 20px 40px rgba(0,0,0,0.1);
  overflow-x: auto; 
  margin-top: 30px; 
}

.chart-section h3 {
    text-align: center;
    color: #4A0072; 
    margin-bottom: 15px;
}
 .chart-section h4 { 
    text-align: center;
    color: #005A8C;
    margin-top: 25px;
    margin-bottom: 10px;
    font-size: 1.1rem;
}
.chart-controls {
    display: flex;
    justify-content: center;
    gap: 20px;
    margin-bottom: 20px;
}
.chart-controls label {
    font-size: 0.9rem;
    color: #333;
    cursor: pointer;
}
 .chart-controls input[type="radio"] {
    margin-right: 5px;
 }

#barChartContainer, #pieAreaConsumptionContainer, #pieEnergyTypeCostContainer, #pieTopEquipmentContainer, #scatterPlotContainer, #hourlyLoadChartContainer {
    min-height: 450px; 
    display: flex; 
    justify-content: center;
    align-items: center;
    position: relative; 
}
.chart-ai-analysis-box { 
    margin-top: 15px;
    padding: 10px;
    background-color: #f8f9fa; 
    border: 1px solid #e9ecef;
    border-radius: 8px;
}
.chart-ai-analysis-box button {
    display: block;
    margin: 0 auto 10px auto; 
    background-color: #28a745; 
    color: white;
    border: none;
    padding: 8px 15px;
    border-radius: 6px;
    font-size: 0.85rem;
    cursor: pointer;
    transition: background-color 0.3s ease;
}
.chart-ai-analysis-box button:hover {
    background-color: #218838;
}
.chart-llm-response-box { 
    font-size: 0.9rem;
    color: #333;
    min-height: 30px;
    padding: 8px;
    background-color: #fff;
    border: 1px solid #eee;
    border-radius: 4px;
    white-space: pre-wrap; 
}
.chart-llm-response-box p { margin-top:0.3em; margin-bottom: 0.3em; line-height: 1.5; } 
.chart-llm-response-box ul { margin-top: 0.3em; margin-bottom: 0.3em; padding-left: 20px;}
.chart-llm-response-box li { margin-bottom: 0.15em; }


.stats-container {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 20px;
  margin-bottom: 30px;
}

.stat-card {
  background: rgba(255,255,255,0.95); 
  padding: 20px;
  border-radius: 16px;
  text-align: center;
  box-shadow: 0 8px 24px rgba(0,0,0,0.1);
  transition: transform 0.3s ease;
}

.stat-card:hover {
    transform: translateY(-5px);
}

.stat-value {
  font-size: 2rem;
  font-weight: bold;
  color: #0077B6; 
  margin-bottom: 5px;
}

.stat-label {
  color: #555; 
  font-size: 0.9rem;
}

.legend { 
  background: rgba(255,255,255,0.95);
  padding: 20px;
  border-radius: 16px;
  margin-top: 10px; 
  box-shadow: 0 8px 24px rgba(0,0,0,0.1);
}

.ai-report-generator-container { 
  background: rgba(255,255,255,0.95);
  padding: 25px;
  border-radius: 16px;
  margin-top: 40px; 
  box-shadow: 0 12px 30px rgba(0,0,0,0.15);
}
.ai-report-generator-container h3 {
  margin: 0 0 20px 0;
  color: #4A0072; 
  text-align: center; 
  font-size: 1.3rem; 
}
.report-controls {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 15px;
    margin-bottom: 15px;
}
.report-controls input[type="text"] {
    padding: 10px;
    border-radius: 6px;
    border: 1px solid #ccc;
    font-size: 0.9rem;
    flex-grow: 1;
    max-width: 300px;
}
.report-controls button {
    background-color: #007bff; 
    color: white;
    padding: 10px 20px;
}
 .report-controls button:hover {
    background-color: #0056b3;
 }
.report-controls a button { 
    background-color: #17a2b8; 
}
.report-controls a button:hover {
    background-color: #138496;
}


#report-progress-bar-container {
    width: 100%;
    background-color: #e0e0e0;
    border-radius: 4px;
    margin-top: 15px;
    display: none; 
}
#report-progress-bar {
    width: 0%;
    height: 20px;
    background-color: #28a745; 
    border-radius: 4px;
    text-align: center;
    line-height: 20px;
    color: white;
    font-size: 0.8rem;
    transition: width 0.5s ease-in-out;
}
 #report-status-message {
    text-align: center;
    font-size: 0.9rem;
    margin-top: 5px;
    color: #333;
 }


.legend h3 { 
  margin: 0 0 15px 0;
  color: #333;
  text-align: center; 
  font-size: 1.2rem; 
}

.legend-item {
  display: flex;
  align-items: center;
  margin-bottom: 10px; 
  font-size: 0.9rem; 
}

.legend-color {
  width: 20px;
  height: 20px;
  border-radius: 4px;
  margin-right: 10px;
  border: 1px solid #ccc;
  flex-shrink: 0; 
}

.sankey-tooltip, .chart-tooltip {
    position: absolute;
    background-color: rgba(0,0,0,0.85);
    color: white;
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 13px; 
    pointer-events: none; 
    opacity: 0;
    transition: opacity 0.2s; 
    box-shadow: 0 2px 8px rgba(0,0,0,0.25);
    z-index: 10; 
}

.loading-spinner {
    border: 4px solid #f3f3f3; 
    border-top: 4px solid #0095DA; 
    border-radius: 50%;
    width: 30px;
    height: 30px;
    animation: spin 1s linear infinite;
    margin: 10px auto; 
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

@media (max-width: 768px) {
    h1 { font-size: 1.8rem; } 
    .subtitle { font-size: 1rem; }
    .intro-section {padding: 15px; font-size: 0.9rem;}
    .intro-section h2 {font-size: 1.2rem;}
    .data-input-section table { font-size: 0.8rem; } 
    .data-input-section th, .data-input-section td { padding: 5px; } /* Reducido para móviles */
    #energyDataTable th, #energyDataTable td { padding: 6px 4px; } /* Específico para la tabla si es necesario ajustar más */
    
    .data-input-section input { padding: 4px; }
    #energyDataTable input[type="text"], 
    #energyDataTable input[type="number"], 
    #energyDataTable select {
        padding: 5px; /* Ajustar padding de inputs en tabla para móviles */
    }

    .controls { padding: 15px; }
    select { padding: 10px 14px; font-size: 0.9rem; }
    #chart-container, .chart-section { padding: 15px; }
    .stat-value { font-size: 1.5rem; }
    .stat-label { font-size: 0.8rem; }
    .legend h3, .ai-report-generator-container h3, .chart-section h3, .chart-section h4 { font-size: 1.1rem; }
    .legend-item { font-size: 0.85rem; }
    .report-controls {flex-direction: column; gap: 10px;}
    .report-controls input[type="text"] {width: 100%; max-width: none;}

}

@media (max-width: 480px) {
    h1 { font-size: 1.6rem; } 
    .intro-section h2 {font-size: 1.1rem;}
    .controls { grid-template-columns: 1fr; }
    .stats-container { grid-template-columns: 1fr; }
    #energyDataTable th, #energyDataTable td {
        font-size: 0.75rem; /* Aún más pequeño para pantallas muy pequeñas */
        padding: 4px 2px;
    }
    #energyDataTable input, #energyDataTable select {
        font-size: 0.75rem;
        padding: 3px;
    }
}