{
const eps_d_mon = mon_controls.eps_d_mon, eps_s_mon = mon_controls.eps_s_mon;
const Qc = 60, Pc = 50, Qmax = 110, Pmax = 120;
const b = Pc / (Qc * eps_d_mon);
const d = Pc / (Qc * eps_s_mon);
const a = Pc + b * Qc;
const c = Pc - d * Qc;
const Qm = (a - c) / (2 * b + d);
const Pm = a - b * Qm;
const MC_at_Qm = c + d * Qm;
const Qs = d3.range(0, Qmax + 1);
const demand = Qs.map(q => ({Q: q, P: a - b * q})).filter(p => p.P >= 0 && p.P <= Pmax);
const mr = Qs.map(q => ({Q: q, P: a - 2 * b * q})).filter(p => p.P >= -Pmax && p.P <= Pmax);
const mc = Qs.map(q => ({Q: q, P: c + d * q})).filter(p => p.P >= 0 && p.P <= Pmax);
const dwlTri = [{Q: Qm, P: Pm}, {Q: Qm, P: MC_at_Qm}, {Q: Qc, P: Pc}];
const dwl = 0.5 * Math.abs(Pm - MC_at_Qm) * Math.abs(Qc - Qm);
const markup = ((Pm - Pc) / Pc) * 100;
return Plot.plot({
width: 820, height: 318, marginLeft: 54, marginRight: 16, marginTop: 20, marginBottom: 38,
style: {fontSize: "12px", fontFamily: "Public Sans, system-ui, sans-serif", color: "#3A332D", background: "transparent"},
x: {label: "Količina (Q) →", domain: [0, Qmax]},
y: {label: "↑ Cijena (P)", domain: [0, Pmax], grid: true},
marks: [
Plot.ruleY([0], {stroke: "#C9C3B8"}),
Plot.line([...dwlTri, dwlTri[0]], {x: "Q", y: "P", stroke: "#6B1F26", strokeWidth: 1, fill: "#D8B5B3", fillOpacity: 0.65}),
Plot.line(demand, {x: "Q", y: "P", stroke: "#2D5A8E", strokeWidth: 2.5}),
Plot.line(mr, {x: "Q", y: "P", stroke: "#3A332D", strokeWidth: 2, strokeDasharray: "5,4"}),
Plot.line(mc, {x: "Q", y: "P", stroke: "#4A6B5C", strokeWidth: 2}),
Plot.ruleY([Pm], {stroke: "#6B6357", strokeDasharray: "4,3"}),
Plot.ruleY([Pc], {stroke: "#6B6357", strokeDasharray: "4,3"}),
Plot.ruleX([Qm], {y1: 0, y2: Pm, stroke: "#6B6357", strokeDasharray: "4,3"}),
Plot.ruleX([Qc], {y1: 0, y2: Pc, stroke: "#6B6357", strokeDasharray: "4,3"}),
Plot.dot([{Q: Qm, P: Pm}], {x: "Q", y: "P", r: 5, fill: "#6B1F26", stroke: "white", strokeWidth: 2}),
Plot.dot([{Q: Qc, P: Pc}], {x: "Q", y: "P", r: 5, fill: "#4A6B5C", stroke: "white", strokeWidth: 2}),
Plot.dot([{Q: Qm, P: MC_at_Qm}], {x: "Q", y: "P", r: 4, fill: "#1C1916", stroke: "white", strokeWidth: 1.5}),
Plot.text([{x: Qmax * 0.8, y: a - b * Qmax * 0.8, label: "D"}], {x: "x", y: "y", text: "label", fill: "#2D5A8E", fontSize: 12, fontWeight: 600, dy: -8}),
Plot.text([{x: Qmax * 0.38, y: a - 2 * b * Qmax * 0.38, label: "MR"}], {x: "x", y: "y", text: "label", fill: "#3A332D", fontSize: 12, fontWeight: 700, dy: -8}),
Plot.text([{x: Qmax * 0.8, y: c + d * Qmax * 0.8, label: "MC"}], {x: "x", y: "y", text: "label", fill: "#4A6B5C", fontSize: 12, fontWeight: 600, dy: -8}),
Plot.text([{x: Qm, y: 2, label: `Q_M = ${Qm.toFixed(1)}`}], {x: "x", y: "y", text: "label", textAnchor: "middle", fontSize: 11, fill: "#6B1F26"}),
Plot.text([{x: Qc, y: 2, label: `Q_C = ${Qc.toFixed(1)}`}], {x: "x", y: "y", text: "label", textAnchor: "middle", fontSize: 11, fill: "#4A6B5C"}),
Plot.text([{x: 2, y: Pmax * 0.96, label: `Mrtvi teret = ${dwl.toFixed(1)} · marža ${markup.toFixed(0)} %`}], {x: "x", y: "y", text: "label", textAnchor: "start", fontSize: 13, fill: "#6B1F26", fontWeight: 700})
]
});
}