/* ============================================================
   Integración Numérica — Método de los Trapecios
   Tema claro (por defecto) + tema oscuro conmutables
   ============================================================ */

:root {
  --sans: 'DM Sans', 'Segoe UI', system-ui, sans-serif;
  --mono: 'JetBrains Mono', ui-monospace, Consolas, monospace;
  --math: Georgia, 'Times New Roman', serif;
}

body[data-tema="claro"] {
  --bg: #edf1f7;
  --card: #ffffff;
  --borde: #e2e8f0;
  --texto: #0f172a;
  --muted: #64748b;
  --input-bg: #ffffff;
  --sutil: #f1f5f9;
  --primario: #3b82f6;
  --primario-hover: #2563eb;
  --topbar: #1e2c49;
  --sidebar: #1e2c49;
  --sombra: 0 1px 3px rgba(15, 23, 42, 0.07);
  --json-bg: #1e293b;
  --jk: #7dd3fc;
  --js: #86efac;
  --jn: #fbbf24;
  --peligro: #dc2626;
}

body[data-tema="oscuro"] {
  --bg: #0f172a;
  --card: #1e293b;
  --borde: #334155;
  --texto: #e2e8f0;
  --muted: #94a3b8;
  --input-bg: #0f172a;
  --sutil: #0f172a;
  --primario: #3b82f6;
  --primario-hover: #2563eb;
  --topbar: #0d1526;
  --sidebar: #0d1526;
  --sombra: 0 1px 3px rgba(0, 0, 0, 0.45);
  --json-bg: #0b1220;
  --jk: #7dd3fc;
  --js: #86efac;
  --jn: #fbbf24;
  --peligro: #f87171;
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  font-family: var(--sans);
  font-size: 14px;
  color: var(--texto);
  background: var(--bg);
  transition: background 0.25s, color 0.25s;
}

svg { width: 16px; height: 16px; flex: none; }

button { font-family: inherit; cursor: pointer; }

/* ============ Barra superior ============ */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 60px;
  padding: 0 20px;
  background: var(--topbar);
  color: #ffffff;
  flex: none;
  transition: background 0.25s;
}

.marca { display: flex; align-items: center; gap: 12px; }

.logo {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: linear-gradient(135deg, #8b5cf6, #6366f1);
  color: #ffffff;
  font-family: var(--math);
  font-style: italic;
  font-size: 22px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 8px rgba(99, 102, 241, 0.45);
}

.marca-texto h1 {
  margin: 0;
  font-size: 15.5px;
  font-weight: 700;
  letter-spacing: 0.01em;
}

.marca-texto p {
  margin: 1px 0 0;
  font-size: 12px;
  color: #94a3b8;
}

.topbar-iconos { display: flex; gap: 6px; }

.icono-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: #b8c4dc;
  transition: background 0.15s, color 0.15s;
}

.icono-btn:hover { background: rgba(255, 255, 255, 0.1); color: #ffffff; }
.icono-btn.activo { color: #fbbf24; }

/* ============ Estructura ============ */

.cuerpo { display: flex; flex: 1; min-height: 0; }

.sidebar {
  width: 188px;
  flex: none;
  display: flex;
  flex-direction: column;
  background: var(--sidebar);
  padding: 14px 10px;
  transition: background 0.25s;
}

.nav { display: flex; flex-direction: column; gap: 4px; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 10px 12px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: #b8c4dc;
  font-size: 13.5px;
  font-weight: 500;
  text-align: left;
  text-decoration: none;
  transition: background 0.15s, color 0.15s;
}

.nav-item:hover { background: rgba(255, 255, 255, 0.07); color: #ffffff; }

.nav-item.activo { background: var(--primario); color: #ffffff; }

.sidebar-pie {
  margin-top: auto;
  padding: 14px 12px 4px;
  border-top: 1px solid rgba(255, 255, 255, 0.09);
  font-size: 11px;
  line-height: 1.6;
  color: #64748b;
}

/* ============ Contenido y tarjetas ============ */

.contenido {
  flex: 1;
  min-width: 0;
  display: grid;
  grid-template-columns: 290px minmax(300px, 1fr) 300px;
  gap: 20px;
  padding: 20px 22px 30px;
  align-items: start;
}

.card {
  background: var(--card);
  border: 1px solid var(--borde);
  border-radius: 12px;
  box-shadow: var(--sombra);
  padding: 18px;
  transition: background 0.25s, border-color 0.25s;
}

.card-titulo {
  margin: 0 0 12px;
  font-size: 15px;
  font-weight: 700;
  color: var(--texto);
}

.controles .card-titulo:not(:first-child) { margin-top: 20px; }

.sub-titulo {
  margin: 18px 0 8px;
  font-size: 13px;
  font-weight: 600;
  color: var(--texto);
}

.sub-titulo:first-of-type { margin-top: 4px; }

/* ============ Pestañas Selector / Editor ============ */

.tabs {
  display: flex;
  gap: 4px;
  background: var(--sutil);
  border: 1px solid var(--borde);
  border-radius: 9px;
  padding: 3px;
  margin-bottom: 12px;
}

.tab {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 7px 10px;
  border: none;
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
  transition: background 0.15s, color 0.15s;
}

.tab svg { width: 14px; height: 14px; }

.tab:hover { color: var(--texto); }

.tab.activo { background: var(--primario); color: #ffffff; }

/* ============ Campos ============ */

.campo label {
  display: block;
  font-size: 12.5px;
  font-weight: 500;
  color: var(--muted);
  margin-bottom: 5px;
}

input[type="number"],
textarea,
select {
  width: 100%;
  background: var(--input-bg);
  border: 1px solid var(--borde);
  border-radius: 8px;
  color: var(--texto);
  font-family: var(--sans);
  font-size: 13.5px;
  padding: 9px 11px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s, background 0.25s;
}

textarea {
  font-family: var(--mono);
  font-size: 13px;
  resize: vertical;
  min-height: 56px;
  line-height: 1.5;
}

input[type="number"]:focus,
input[type="text"]:focus,
textarea:focus,
select:focus {
  border-color: var(--primario);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.18);
}

.fila-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.ejemplos {
  margin: 8px 0 0;
  font-size: 11.5px;
  color: var(--muted);
}

.ejemplos code {
  font-family: var(--mono);
  font-size: 10.5px;
  background: var(--sutil);
  border: 1px solid var(--borde);
  border-radius: 4px;
  padding: 1px 5px;
}

.error {
  margin: 8px 0 0;
  font-size: 12px;
  line-height: 1.5;
  color: var(--peligro);
}

/* ============ Stepper de trapecios ============ */

.stepper {
  display: flex;
  border: 1px solid var(--borde);
  border-radius: 8px;
  overflow: hidden;
}

.stepper button {
  flex: none;
  width: 44px;
  border: none;
  background: var(--sutil);
  color: var(--texto);
  font-size: 18px;
  font-weight: 600;
  transition: background 0.15s, color 0.15s;
}

.stepper button:hover { background: var(--primario); color: #ffffff; }

.stepper input {
  flex: 1;
  border: none;
  border-left: 1px solid var(--borde);
  border-right: 1px solid var(--borde);
  border-radius: 0;
  text-align: center;
  font-family: var(--mono);
  font-size: 14px;
  font-weight: 600;
  -moz-appearance: textfield;
  appearance: textfield;
}

.stepper input::-webkit-outer-spin-button,
.stepper input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

.stepper input:focus { box-shadow: none; }

/* ============ Deslizador de trapecios ============ */

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 22px;
  margin-top: 10px;
  background: transparent;
  cursor: pointer;
}

input[type="range"]::-webkit-slider-runnable-track {
  height: 3px;
  background: linear-gradient(90deg, var(--primario), rgba(148, 163, 184, 0.35));
  border-radius: 2px;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  margin-top: -6.5px;
  background: var(--primario);
  border: 3px solid var(--card);
  border-radius: 4px;
  box-shadow: 0 0 0 1px var(--primario);
}

input[type="range"]::-moz-range-track {
  height: 3px;
  background: linear-gradient(90deg, var(--primario), rgba(148, 163, 184, 0.35));
  border-radius: 2px;
}

input[type="range"]::-moz-range-thumb {
  width: 10px;
  height: 10px;
  background: var(--primario);
  border: 3px solid var(--card);
  border-radius: 4px;
  box-shadow: 0 0 0 1px var(--primario);
}

/* ============ Botones ============ */

.btn-actualizar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  width: 100%;
  margin-top: 20px;
  padding: 11px;
  border: none;
  border-radius: 9px;
  background: var(--primario);
  color: #ffffff;
  font-size: 14px;
  font-weight: 600;
  transition: background 0.15s, transform 0.1s;
}

.btn-actualizar:hover { background: var(--primario-hover); }
.btn-actualizar:active { transform: translateY(1px); }

.btn-actualizar.girando svg { animation: girar 0.5s ease; }

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

.btn-outline {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 9px 12px;
  background: transparent;
  border: 1px solid var(--borde);
  border-radius: 8px;
  color: var(--texto);
  font-size: 13px;
  font-weight: 600;
  transition: border-color 0.15s, background 0.15s;
}

.btn-outline:hover { border-color: var(--primario); background: rgba(59, 130, 246, 0.08); }

.btn-outline.auto { width: auto; }

/* ============ Columna central ============ */

.centro {
  display: flex;
  flex-direction: column;
  gap: 20px;
  min-width: 0;
}

/* --- Tarjeta de área --- */

.area-card {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px 28px;
}

.area-izq .card-titulo { margin-bottom: 4px; }

.area-num {
  font-size: clamp(2.1rem, 3.4vw, 2.9rem);
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.1;
  color: var(--texto);
  font-variant-numeric: tabular-nums;
}

.area-der { text-align: right; }

.integral {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: var(--math);
  font-size: 17px;
  color: var(--texto);
}

.int-sim { font-size: 2.3em; line-height: 0.8; font-style: normal; }

.int-lims {
  display: inline-flex;
  flex-direction: column;
  font-size: 0.62em;
  line-height: 1.15;
  margin-left: -2px;
}

.int-lims sub { order: 2; }
.int-lims sup { order: 1; }

.int-expr em { font-style: italic; }
.int-expr strong { font-weight: 700; }

.con-n {
  margin: 6px 0 0;
  font-size: 12px;
  color: var(--muted);
}

/* --- Gráfica --- */

.grafica-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 6px 16px;
  margin-bottom: 12px;
}

.grafica-head .card-titulo { margin: 0; }

.leyenda {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 18px;
  font-size: 12px;
  color: var(--muted);
}

.ley-item { display: inline-flex; align-items: center; gap: 7px; }

.ley-item span { font-family: var(--mono); font-size: 11.5px; }

.sw { display: inline-block; flex: none; }

.sw.linea { width: 18px; height: 3px; border-radius: 2px; background: #2563eb; }

.sw.trap {
  width: 12px;
  height: 12px;
  border-radius: 3px;
  background: rgba(139, 92, 246, 0.25);
  border: 1px solid #8b5cf6;
}

.canvas-wrap {
  position: relative;
  width: 100%;
  height: 380px;
  min-height: 200px;
  background: var(--card);
  border-radius: 8px;
}

#grafica { display: block; width: 100%; height: 100%; }

/* --- Detalle del cálculo --- */

.detalle { padding: 0; overflow: hidden; }

.detalle-head {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  padding: 15px 18px;
  border: none;
  background: transparent;
  color: var(--texto);
  font-size: 14px;
  font-weight: 600;
  text-align: left;
}

.detalle-head:hover { background: rgba(59, 130, 246, 0.05); }

.detalle-head .chev { width: 15px; height: 15px; transition: transform 0.25s; }

.detalle.cerrado .detalle-head .chev { transform: rotate(-90deg); }

.detalle-body {
  display: grid;
  grid-template-rows: 1fr;
  transition: grid-template-rows 0.3s ease;
}

.detalle.cerrado .detalle-body { grid-template-rows: 0fr; }

.detalle-inner {
  overflow: hidden;
  padding: 0 18px 18px;
}

.tabla {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 14px;
}

.tabla th {
  padding: 8px 12px;
  background: var(--sutil);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  text-align: left;
}

.tabla th:first-child { border-radius: 8px 0 0 8px; }
.tabla th:last-child { border-radius: 0 8px 8px 0; }

.tabla td {
  padding: 10px 12px;
  font-family: var(--mono);
  font-size: 13px;
  color: var(--texto);
  border-top: 1px solid var(--borde);
}

.formula-box {
  background: var(--sutil);
  border-radius: 9px;
  padding: 16px 14px;
  text-align: center;
  font-family: var(--math);
  font-size: 17px;
  color: var(--texto);
}

.formula-box em { font-style: italic; }
.formula-box big { font-size: 1.5em; font-weight: 300; vertical-align: -0.12em; }

.frac {
  display: inline-flex;
  flex-direction: column;
  text-align: center;
  vertical-align: middle;
  font-size: 0.72em;
  line-height: 1.2;
  margin: 0 2px;
}

.frac .num { border-bottom: 1.5px solid currentColor; padding: 0 5px; }

.sum {
  display: inline-flex;
  flex-direction: column;
  font-size: 1.15em;
  line-height: 1;
  vertical-align: middle;
  margin: 0 2px;
}

.sum-lim, .sum-sub { font-size: 0.5em; font-style: italic; }

/* ============ Configuración ============ */

.desc {
  margin: 7px 0 0;
  font-size: 11.5px;
  line-height: 1.55;
  color: var(--muted);
}

.carga-fila {
  display: flex;
  align-items: center;
  gap: 10px;
}

.nombre-archivo {
  font-size: 11.5px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.json-box {
  position: relative;
  background: var(--json-bg);
  border-radius: 9px;
  margin-top: 4px;
}

.json-box pre {
  margin: 0;
  padding: 14px 15px;
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.65;
  color: #e2e8f0;
  overflow-x: auto;
}

.jk { color: var(--jk); }
.js { color: var(--js); }
.jn { color: var(--jn); }

.copiar {
  position: absolute;
  top: 8px;
  right: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 6px;
  color: #94a3b8;
  transition: color 0.15s, border-color 0.15s;
}

.copiar:hover { color: #ffffff; border-color: #64748b; }

.copiar svg { width: 13px; height: 13px; }

/* ============ Modal ============ */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 60;
}

.modal-overlay[hidden] { display: none; }

.modal { width: min(540px, 100%); max-height: 85vh; overflow-y: auto; }

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}

.modal-head .card-titulo { margin: 0; }

.icono-cerrar {
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 15px;
  padding: 4px 8px;
  border-radius: 6px;
}

.icono-cerrar:hover { background: var(--sutil); color: var(--texto); }

.modal-body h3 {
  margin: 16px 0 5px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--muted);
}

.modal-body p { margin: 0; font-size: 13px; line-height: 1.7; }

.modal-body code {
  font-family: var(--mono);
  font-size: 11.5px;
  background: var(--sutil);
  border: 1px solid var(--borde);
  border-radius: 4px;
  padding: 1px 5px;
}

/* ============ Toast ============ */

.toast {
  position: fixed;
  bottom: 22px;
  left: 50%;
  transform: translate(-50%, 16px);
  max-width: min(90vw, 480px);
  padding: 11px 18px;
  background: #1e293b;
  border: 1px solid #3b82f6;
  border-radius: 9px;
  color: #e2e8f0;
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s, transform 0.25s;
  z-index: 70;
}

.toast.visible { opacity: 1; transform: translate(-50%, 0); }
.toast.error { border-color: #ef4444; }

/* ============ Responsive ============ */

@media (max-width: 1180px) {
  .contenido { grid-template-columns: 290px minmax(0, 1fr); }
  .config { grid-column: 1 / -1; }
}

@media (max-width: 860px) {
  .cuerpo { flex-direction: column; }
  .sidebar {
    width: auto;
    flex-direction: row;
    align-items: center;
    padding: 8px 12px;
  }
  .nav { flex-direction: row; gap: 6px; }
  .nav-item { width: auto; }
  .sidebar-pie { display: none; }
  .contenido { grid-template-columns: 1fr; padding: 14px; }
  .area-der { text-align: left; }
  .canvas-wrap { height: 300px; }
}
