!rows.length) { setStatus('Could not parse CSV'); return; }
      state.rows = rows;
      const firstRow = rows[0] || [];
      if (state.hasHeader) {
        state.headers = firstRow.map(String);
      } else {
        state.headers = [];
      }
      state.labelColumn = 0;
      state.valueColumn = Math.min(1, (firstRow.length||2)-1);
      state.datasets = [];
      state.datasetColors = {};
      rebuildColumnSelectors();
      updateVisibilityByType();
      ensureChart();
      setStatus(`Loaded ${r