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

body {
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  background: #f0f4f8;
  color: #1a1a2e;
  min-height: 100vh;
}

/* ── Cabecera ── */
header {
  background: #1a1a2e;
  color: white;
  padding: 0.75rem 2rem;
  text-align: center;
}
header h1 { font-size: 1.25rem; margin-bottom: 0.15rem; }
header p  { color: #a0aec0; font-size: 0.85rem; }

/* ── Layout de dos columnas ── */
.calculator-layout {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
  padding: 1.5rem;
  max-width: 1300px;
  margin: 0 auto;
  align-items: start;
}
@media (max-width: 900px) { .calculator-layout { grid-template-columns: 1fr; } }

/* ── Paneles ── */
.inputs-panel,
.results-panel {
  background: white;
  border-radius: 12px;
  padding: 1.25rem;
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
  position: relative;
  /* overflow visible so que los tooltips no queden recortados */
  overflow: visible;
}
.results-panel[hidden] { display: none; }

/* Indicador de resultados desactualizados */
.results-panel.results-stale::after {
  content: '';
  position: absolute; inset: 0;
  background: rgba(203,213,224,0.55);
  border-radius: 12px;
  pointer-events: none;
  z-index: 10;
}
.results-panel.results-stale::before {
  content: 'Resultados desactualizados — recalcule';
  position: absolute;
  top: 0.6rem; right: 0.75rem;
  z-index: 11;
  font-size: 0.72rem; font-weight: 600; color: #2d3748;
  background: rgba(255,255,255,0.92);
  padding: 0.18rem 0.55rem;
  border-radius: 4px;
  pointer-events: none;
}

/* ── Títulos de sección ── */
h2 {
  font-size: 1.05rem;
  margin-bottom: 0.9rem;
  color: #2d3748;
  border-bottom: 2px solid #e2e8f0;
  padding-bottom: 0.4rem;
}

/* ── Fieldsets ── */
fieldset {
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  padding: 0.6rem 0.85rem 0.45rem;
  margin-bottom: 0.7rem;
  /* overflow visible para tooltips */
  overflow: visible;
}
legend {
  font-weight: 600;
  color: #4a5568;
  padding: 0 0.4rem;
  font-size: 0.82rem;
  letter-spacing: 0.02em;
}

/* ── Rejilla de 2 columnas con etiquetas compactas ── */
.fields-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  column-gap: 0.8rem;
  overflow: visible;
}
.fields-grid .span2 { grid-column: span 2; }

/*
  Estructura de cada label:
    <label>
      <span>Texto</span>
      <i class="tip" data-tip="...">ⓘ</i>   ← fuera del <span>
      <input ...>
    </label>
  → flex-row: [texto flex-1] [ⓘ] [input fijo]
*/
.fields-grid label {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 0.35rem;
  margin-bottom: 0.28rem;
  font-size: 0.80rem;
  color: #4a5568;
  overflow: visible;      /* tooltips no deben recortarse */
}

/* El <span> del texto ocupa el espacio disponible */
.fields-grid label > span {
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Inputs numéricos y selects: ancho fijo a la derecha */
.fields-grid label input[type="number"],
.fields-grid label select {
  width: 112px;
  flex-shrink: 0;
  text-align: right;
}

/* Inputs de texto (listas separadas por comas) en span2: toman el espacio restante */
.fields-grid label.span2 input[type="text"] {
  flex: 1;
  width: auto;
  min-width: 0;
  text-align: left;
}

/* Selects en span2: también a ancho completo */
.fields-grid label.span2 select {
  flex: 1;
  width: auto;
}

/* En span2, el texto del label toma solo su ancho natural para que
   el control (select, chip-input) llene el espacio restante */
.fields-grid label.span2 > span {
  flex: 0 0 auto;
}

/* ── Controles de formulario ── */
input[type="number"],
input[type="text"],
select {
  padding: 0.32rem 0.55rem;
  border: 1px solid #cbd5e0;
  border-radius: 6px;
  font-size: 0.86rem;
  background: #fafbfc;
  width: 100%;
  transition: border-color 0.15s;
  -moz-appearance: textfield;
  appearance: textfield;
}
input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
input:focus, select:focus {
  outline: none;
  border-color: #4299e1;
  box-shadow: 0 0 0 3px rgba(66,153,225,0.18);
  background: #fff;
}

/* ── Icono de ayuda ⓘ ── */
.tip {
  font-style: normal;
  font-size: 0.78rem;       /* más grande que antes */
  color: #718096;           /* más oscuro, más visible */
  cursor: help;
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  vertical-align: middle;
  user-select: none;
  flex-shrink: 0;
  width: 1rem;
  height: 1rem;
}

/* El tooltip aparece POR ENCIMA del icono, centrado horizontalmente */
.tip::after {
  content: attr(data-tip);
  position: absolute;
  bottom: calc(100% + 7px);
  left: 50%;
  transform: translateX(-50%);
  background: #2d3748;
  color: #e2e8f0;
  font-size: 0.73rem;
  font-weight: 400;
  padding: 0.45rem 0.7rem;
  border-radius: 6px;
  width: 230px;
  white-space: normal;
  line-height: 1.5;
  pointer-events: none;
  z-index: 500;
  box-shadow: 0 4px 12px rgba(0,0,0,0.28);
  opacity: 0;
  transition: opacity 0.15s;
}
/* Pequeño triángulo apuntando hacia abajo */
.tip::before {
  content: '';
  position: absolute;
  bottom: calc(100% + 1px);
  left: 50%;
  transform: translateX(-50%);
  border: 5px solid transparent;
  border-top-color: #2d3748;
  pointer-events: none;
  z-index: 501;
  opacity: 0;
  transition: opacity 0.15s;
}
.tip:hover::after,
.tip:hover::before { opacity: 1; }

/* ── Botón Calcular ── */
button.btn-calculate {
  width: 100%;
  padding: 0.65rem 1rem;
  background: linear-gradient(135deg, #1a1a2e 0%, #2d2d4e 100%);
  color: white;
  border: none;
  border-radius: 8px;
  font-size: 0.92rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  cursor: pointer;
  margin-top: 0.4rem;
  box-shadow: 0 2px 8px rgba(26,26,46,0.35);
  transition: transform 0.1s, box-shadow 0.15s;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
}
button.btn-calculate::before { content: '▶'; font-size: 0.68em; opacity: 0.85; }
button.btn-calculate:hover   { transform: translateY(-1px); box-shadow: 0 4px 14px rgba(26,26,46,0.45); }
button.btn-calculate:active  { transform: translateY(0);    box-shadow: 0 1px 4px rgba(26,26,46,0.3); }
button.btn-calculate:disabled {
  background: linear-gradient(135deg, #a0aec0, #718096);
  box-shadow: none; transform: none; cursor: not-allowed;
}

/* ── Spinner de carga ── */
.spinner-overlay {
  display: none;
  position: absolute;
  inset: 0;
  background: rgba(255,255,255,0.82);
  border-radius: 12px;
  z-index: 20;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.9rem;
}
.spinner-overlay.active { display: flex; }
.spinner {
  width: 40px; height: 40px;
  border: 4px solid #e2e8f0;
  border-top-color: #1a1a2e;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.spinner-label { font-size: 0.84rem; color: #4a5568; font-weight: 500; }

/* ── Rejilla 2×2 de gráficas ── */
.plots-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.8rem;
  margin-top: 0.4rem;
}
.plot-card {
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  overflow: hidden;
}
.plot-card h3 {
  font-size: 0.72rem;
  font-weight: 700;
  color: #4a5568;
  padding: 0.32rem 0.55rem;
  background: #edf2f7;
  border-bottom: 1px solid #e2e8f0;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.plot-card img { width: 100%; height: auto; display: block; }

/* ── Selector de modo (Matriz de flujo / Datos experimentales) ── */
.mode-toggle {
  display: flex;
  width: 100%;
  border: 1px solid #cbd5e0;
  border-radius: 8px;
  overflow: hidden;
  margin-bottom: 1rem;
}
.mode-btn {
  flex: 1;
  padding: 0.48rem 0.6rem;
  font-size: 0.84rem;
  font-weight: 600;
  border: none;
  background: #fff;
  color: #4a5568;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  user-select: none;
  line-height: 1.3;
}
.mode-btn:not(:last-child) { border-right: 1px solid #cbd5e0; }
.mode-btn:hover:not(.active) { background: #f7fafc; }
.mode-btn.active {
  background: #1a1a2e;
  color: #fff;
}

/* Separador visual entre las dos secciones de modo */
.mode-section { display: block; }
.mode-section[hidden] { display: none; }

/* ── Banner de error ── */
.error-banner {
  display: none;
  background: #fff5f5;
  border: 1px solid #feb2b2;
  border-radius: 8px;
  padding: 0.7rem 0.9rem;
  color: #c53030;
  font-size: 0.85rem;
  margin-bottom: 0.8rem;
}
.error-banner.active { display: block; }

/* ── Metadatos del resultado ── */
.result-meta {
  font-size: 0.72rem;
  color: #a0aec0;
  margin-bottom: 0.6rem;
  font-style: italic;
}

/* ── Chip input (listas de valores numéricos) ── */
.chip-input {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 3px;
  padding: 3px 6px;
  min-height: 32px;
  border: 1px solid #cbd5e0;
  border-radius: 6px;
  background: #fafbfc;
  cursor: text;
  transition: border-color 0.15s;
  flex: 1;
  min-width: 0;
}
.chip-input:focus-within {
  border-color: #4299e1;
  box-shadow: 0 0 0 3px rgba(66,153,225,0.18);
  background: #fff;
}
.chip {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 1px 7px 1px 8px;
  background: #edf2f7;
  border: 1px solid #cbd5e0;
  border-radius: 100px;
  font-size: 0.78rem;
  font-weight: 600;
  color: #4a5568;
  white-space: nowrap;
  line-height: 1.5;
}
.chip-remove {
  border: none;
  background: none;
  color: #a0aec0;
  cursor: pointer;
  font-size: 0.82rem;
  padding: 0;
  line-height: 1;
  display: flex;
  align-items: center;
}
.chip-remove:hover { color: #e53e3e; }
.chip-entry {
  border: none;
  outline: none;
  font: inherit;
  font-size: 0.83rem;
  min-width: 52px;
  width: 52px;
  padding: 1px 2px;
  background: transparent;
  color: #2d3748;
}
.chip-entry::placeholder { color: #a0aec0; font-weight: 400; }

.chip-clear-all {
  margin-left: auto;
  flex-shrink: 0;
  border: none;
  background: none;
  font-size: 0.70rem;
  color: #a0aec0;
  cursor: pointer;
  padding: 1px 4px;
  border-radius: 4px;
  white-space: nowrap;
  line-height: 1;
}
.chip-clear-all:hover { color: #e53e3e; background: #fff5f5; }
